Pandas/GroupBy & aggregation 9 min

GroupBy and aggregation

Split, apply, combine.

groupbyaggtransform

groupby splits rows into buckets by one or more keys, applies a function to each bucket and combines the results back into a frame.

python · editable
loading editor…

agg computes several statistics at once and names the output columns; as_index=False keeps the key as a normal column.

python · editable
loading editor…

transform returns a value per original row instead of per group — perfect for group shares or group-mean centring.

python · editable
loading editor…