Pandas: tabular data
- Load CSV and Excel files into pandas DataFrames
- Filter rows and select columns with boolean indexing
- Group data with
.groupby()and aggregate with.sum(),.mean() - Handle missing values with
.dropna()and.fillna()
Pandas is the lingua franca of data engineering, ML feature pipelines, and analyst-facing ETL — every Airflow DAG and Jupyter notebook eventually touches a DataFrame. Staff engineers avoid .apply() and .iterrows() in favor of vectorized column ops, groupby().agg(), and merge with explicit how= and validate= to catch join-cardinality bugs early.
- Chained assignment like
df[df.x > 0]['y'] = 1— triggersSettingWithCopyWarning; use.loc[mask, 'y'] = 1. - Merging without
validate='one_to_one'— silent row explosions from duplicate keys ruin downstream counts. - Storing strings as
objectdtype — 10× more memory thancategoryfor low-cardinality columns like brand or region.
If NumPy is arrays, pandas is tables. The DataFrame is the central type — rows, named columns, mixed dtypes.
Essentials
df["col"]— a Series (one column)df[df["x"] > 5]— boolean filterdf.groupby("col").agg(...)— split-apply-combinedf.sort_values("col")·df.merge(other, on="key")pd.read_csv(io.StringIO(...))— parse CSVs
Pyodide reality
Pandas is large (~15 MB total with NumPy). First import is slow, then cached. Good for medium data (~100k rows); huge datasets are out of scope for a browser.
Try it
- Add a
countrycolumn todfand group by it. - Sort by year descending and take the top 3.
3 graded exercises
Write the code, click Check. We’ll tell you exactly what to fix.
- Exercise 1
Build a DataFrame
dffrom{"name": ["Ada", "Grace", "Linus"], "age": [30, 40, 50]}. Print its shape — expected:(3, 2). - Exercise 2
From the same
df, buildolder— a DataFrame containing only rows whereage >= 40. Then printlist(older["name"]). Expected:['Grace', 'Linus']. - Exercise 3
Sort
dfbyagedescending, print thenamecolumn of the result. Expected: names in orderLinus,Grace,Ada.