Multiple Aggregations
The agg() function provides powerful ways to apply multiple aggregations to grouped data.
Named Aggregations
Use named tuples for clear output:
Loading Pandas Playground...
Different Aggregations per Column
Apply different functions to different columns:
Loading Pandas Playground...
Custom Aggregation Functions
Use your own functions:
Loading Pandas Playground...
Aggregation with Lambda
Use lambda for inline functions:
Loading Pandas Playground...
Resetting Index After Aggregation
Convert multi-index to regular columns:
Loading Pandas Playground...
Transform vs Aggregate
Transform returns same-size output:
Loading Pandas Playground...
Exercise: Multiple Stats
Loading Exercise...
Exercise: Add Group Mean
Loading Exercise...
Key Points
agg()for multiple aggregations- Named aggregations:
name=('column', 'function') - Dict syntax for different functions per column
- Custom functions work with
agg() transform()returns same-length outputreset_index()flattens grouped results

