pandas
Predict the table, then run it
Filtering, grouping, joining and reshaping all change the size of a table, and being good at this is being able to say what size before you look. Seven runs of drills and builds, ending with the question none of the tutorials ask: when you assign into a frame, does the write actually land?
- Modules
- 7
- Drills
- 10
- Build steps
- 7
- Time
- ~4h
Walk out able to
Predict a merge’s row count from its keys, move a table between long and wide, and say whether a write reaches the frame — before running any of it.
What you work through
Frames, dtypes, selection
What a column really holds, and reaching one exact row.
Grouping and joining
One row per group — and the merge that doubled your rows.
Long, wide and back
Melt, pivot and stack, as arithmetic rather than magic.
Where a write lands
The warning, what replaced it, and the report you build.
The pitch
What you practise, and what you leave with
A report script: two tables in, unmatched rows discarded, totals by town and year, one wide CSV out, checked against a total.
You will practise
- Selecting by label, position and mask
- Grouping, aggregating, and missing keys
- Merge row counts and column names
- Long and wide, and where a write lands
Afterwards you can
- Call a merge’s row count before running it
- Move a table between long and wide
- Spot chained assignment on sight
- Read pandas 2.x code on pandas 3.x
Modules
7 modules, 25 items
Lessons explain one idea. Drills repeat it until it sticks. Build steps make something that exists afterwards.
- 1
Get a frame and see what is in it
~22 minBuild a frame, read its dtypes, and say how many values are really there.
- LessonWhy a frame and not a list of dicts4 min
- Build stepBuild your first frame and read it7 min
- DrillSay what dtype a column will get11 min
- 2
Select the rows you meant
~42 minReach any subset by label, by position or by mask — and know the count first.
- LessonTell loc and iloc apart for good11 min
- Build stepFilter sixty rows with a mask8 min
- DrillCount the rows a filter keeps12 min
- DrillTell a label from a position11 min
- 3
One row per group
~40 minSplit by a key and predict both the value and the shape of what comes back.
- LessonCollapse a frame to one row per town10 min
- Build stepTotal fifty readings by town6 min
- DrillCount the rows a grouping returns12 min
- DrillAggregate a column with gaps in it12 min
- 4
Line two frames up on a key
~41 minPredict a merge’s row count from the keys, and catch the multiplication early.
- LessonDecide which rows a merge keeps11 min
- Build stepPredict an outer join, then run it6 min
- DrillCount the rows a merge returns13 min
- DrillName the columns a merge produces11 min
- 5
Long and wide are one table
~28 minMove a table between the two encodings and say what shape it lands in.
- LessonTurn a long table wide, and back10 min
- Build stepPivot forty-five readings into a grid6 min
- DrillPredict the shape after a reshape12 min
- 6
The copy you thought was a view
~33 minSay whether a write reaches the frame — on your pandas, and on the one before it.
- LessonSpot chained assignment on sight10 min
- LessonRead pandas 2.x code on pandas 3.x10 min
- DrillSay where a write lands, on sight13 min
- 7
Build the report
~42 minRecall the calls from memory, then turn two tables into one wide report.
- DrillWrite the call that does what you meant12 min
- Build stepThrow away the visits with no town10 min
- Build stepTotal the minutes by town and year8 min
- LessonTurn the totals into a wide report12 min
More in Data & databases
Keep going
SQL: Queries
Say what a query returns before you run it.
Intermediate~3h6 modules
ORMs
Count the queries before the mapper sends them.
Intermediate~4h6 modules
SQL: Joins & NULL
The rows that found no partner, and the values that are not there.
Advanced~4h5 modules
SQL: Advanced
The clause you did not write decided the number.
Advanced~6h7 modules
Say what the table will be before you run the line.
The first item is free. ~4h of focused work, at your own pace.
Intermediate~4h7 modules