Stop Chaining apply(): pandas Named Aggregation Does It in One Pass
pandas named aggregation replaces chained apply() calls and MultiIndex flattening with one declarative groupby-agg call. A worked example, the performance trade-offs, and where it can't help.