Guided Notes

GroupBy

Split-apply-combine: grouping rows, aggregating with sum, mean, count, and agg, and grouping by several columns.

Split, apply, combine

Slide 1 / 5

groupby answers questions like "total sales per region" or "average salary per department". It works in three steps:

1. Split the rows into groups that share a value. 2. Apply a calculation to each group. 3. Combine the results into a new table.

df.groupby('region')['sales'].sum()

It's the pandas version of SQL's GROUP BY.