Python for Economists, A to Z
Python from your first variable to a regression on real Kenyan data. Twelve modules built around what an economist actually does with Python: pandas DataFrames, NumPy arrays, statsmodels regressions, matplotlib charts, and the workflow that ties it all together. Every exercise runs real Python in your browser.
12
Modules
~10h 40m
Reading time
Beginner
Level
Self-paced
Format
Hands-on practice environment
Real Python in your browser. Pandas, NumPy, matplotlib pre-loaded.
CPython compiled to WebAssembly via Pyodide. The same three Kenyan datasets used across our published analyses are pre-defined as DataFrames the moment you start, so every exercise runs against real data. From print("hello") to df.groupby("year").agg(...).
Syllabus
- 01→
Hello, Python — variables and types
The interactive REPL, basic types, the four operators, and why dynamic typing both helps and hurts.
~35 minModule 01 - 02→
Strings, numbers, and formatting
f-strings, integer vs float, string methods, and the formatting tricks that make output readable.
~40 minModule 02 - 03→
Lists, tuples, dicts, sets
The four built-in collections, when each one is right, and how to convert between them.
~50 minModule 03 - 04→
Control flow: if, for, while
Conditionals, iteration, and the truthiness rules that surprise everyone in their first week.
~45 minModule 04 - 05→
Functions and scope
Defining, calling, default arguments, *args and **kwargs, and the LEGB scope rule.
~50 minModule 05 - 06→
Comprehensions and lambda
List, dict, and set comprehensions; the genuinely-Pythonic way to transform collections.
~40 minModule 06 - 07→
NumPy arrays and vectorisation
ndarrays, broadcasting, slicing, and why vectorised code is 100x faster than Python loops.
~55 minModule 07 - 08→
Pandas: Series and DataFrames
Creating, indexing, selecting, and the loc/iloc distinction that catches every beginner.
~60 minModule 08 - 09→
Pandas data wrangling
Filter, group-by, merge, pivot, melt — the five verbs that cover 90% of analysis work.
~65 minModule 09 - 10→
Plotting with matplotlib
Line, bar, scatter, histogram. Basic styling, subplots, and the explicit fig/ax pattern.
~50 minModule 10 - 11→
Regression with statsmodels
OLS via statsmodels, robust SEs, formula-style, predict, and reading the summary table.
~60 minModule 11 - 12→
Three real analyses on Kenyan data
Replicate the bank-rates spread, the pension allocation shift, and the M-PESA growth curve — entirely in Python.
~90 minModule 12
How to use this course
Start with module 01 if the material is new; skip ahead if you have prior exposure. Each module is self-contained but the arc is sequential — the projects in the final module assume the toolkit from modules 1-11. Every module ends with key takeaways and a curated further-reading list with primary sources.