Group by category → compute stats per group (like Excel pivot table).
df.groupby("species")["petal_length"].mean()
# Average petal length per flower species
Multiple aggregations:
df.groupby("city").agg({
"age": "mean",
"salary": ["min", "max", "mean"]
})
Reshape data — summarize with rows/columns.
pd.pivot_table(df,
values="salary",
index="department",
columns="year",
aggfunc="mean")
Used in ML: compare features across categories.