Summaries on Multiple Columns in Pandas – Advanced Aggregations 2026
When performing data manipulation, you often need different summary statistics for different columns at the same time. In 2026, Pandas makes this elegant and efficient using the .agg() method with multiple columns and custom functions.
TL;DR — Best Ways to Summarize Multiple Columns
- Use dictionary syntax in
.agg()for full control - Named aggregation syntax for clean column names
- Combine with
groupby()for segmented analysis - Use lambda or custom functions when needed
1. Basic Multi-Column Aggregation
import pandas as pd
df = pd.read_csv("sales_data.csv", parse_dates=["order_date"])
summary = df.agg({
"amount": ["sum", "mean", "median", "min", "max", "std"],
"quantity": ["sum", "mean", "max"],
"customer_id": "nunique",
"region": "nunique"
}).round(2)
print(summary)
2. Grouped Summaries on Multiple Columns (Most Common Pattern)
result = (
df
.groupby(["region", df["order_date"].dt.to_period("M")])
.agg({
"amount": ["sum", "mean", "count"],
"quantity": ["sum", "mean"],
"customer_id": "nunique",
"product_id": "nunique"
})
.round(2)
)
# Flatten multi-level columns
result.columns = ["total_sales", "avg_sale", "order_count",
"total_quantity", "avg_quantity", "unique_customers", "unique_products"]
print(result)
3. Named Aggregation (Cleanest & Recommended in 2026)
monthly_summary = (
df
.groupby(["region", df["order_date"].dt.to_period("M")])
.agg(
total_sales=("amount", "sum"),
avg_sale=("amount", "mean"),
order_count=("amount", "count"),
total_qty=("quantity", "sum"),
unique_customers=("customer_id", "nunique")
)
.round(2)
.reset_index()
)
print(monthly_summary)
4. Using Custom Functions on Multiple Columns
def range_func(x):
return x.max() - x.min()
summary = (
df
.groupby("region")
.agg(
sales_range=("amount", range_func),
qty_range=("quantity", range_func),
avg_price=("amount", lambda x: x.mean() / x.count() if x.count() > 0 else 0)
)
)
Best Practices in 2026
- Use **named aggregation** syntax for readable column names
- Always round final results for clean output
- Combine with
.reset_index()when you need flat DataFrames - Define small helper functions for complex calculations
- Use method chaining for better readability
Conclusion
Summarizing multiple columns efficiently is a core skill in Pandas data manipulation. In 2026, the combination of .agg() with named aggregation and proper grouping gives you maximum flexibility and clean, professional-looking results. Master these patterns and your summary reports will become much more insightful and maintainable.
Next steps:
- Take one of your current groupby operations and rewrite it using named aggregation syntax