GroupBy with Multiple Aggregations
Often you need multiple statistics per group. Use agg() to apply several functions at once.
df.groupby('category')['price'].agg(['mean', 'min', 'max', 'count'])
This gives mean, minimum, maximum, and count for each category.
Different aggregations per column:
df.groupby('store').agg({
'sales': 'sum',
'customers': 'mean',
'rating': ['min', 'max']
})
Named aggregations for clean column names:
df.groupby('region').agg(
total_sales=('sales', 'sum'),
avg_order=('order_value', 'mean')
)
For comprehensive GroupBy techniques, see my Pandas course.