GroupBy & Aggregation
Split-apply-combine: pandas' most powerful single idea.
works in three steps you don't have to write
yourself: split the data into groups by some key, apply a function to
each group, then combine the results back together. .agg/.apply
return one row per group (the data shrinks); .transform returns one row
per original row (same shape as the input, values broadcast per group).
| Call | Use it for | Example |
|---|---|---|
| pull out just one group |
|
| keep whole groups matching a group-level condition | keep only groups where |
| spreadsheet-style cross-tab | rows=animal, columns=year, values=mean age |
Now practice it
Exercises that use what this lesson just covered.