Get startedGet started for free

Multiple grouped summaries

Earlier in this chapter, you saw that the .agg() method is useful to compute multiple statistics on multiple variables. It also works with grouped data. You can use built-in functions like min, max, mean, and median.

sales is available and pandas is imported as pd.

This exercise is part of the course

Data Manipulation with pandas

View Course

Exercise instructions

  • Get the min, max, mean, and median of weekly_sales for each store type using .groupby() and .agg(). Store this as sales_stats.
  • Get the min, max, mean, and median of unemployment and fuel_price_usd_per_l for each store type. Store this as unemp_fuel_stats.

Hands-on interactive exercise

Have a go at this exercise by completing this sample code.

# For each store type, aggregate weekly_sales: get min, max, mean, and median
sales_stats = ____

# Print sales_stats
print(sales_stats)

# For each store type, aggregate unemployment and fuel_price_usd_per_l: get min, max, mean, and median
unemp_fuel_stats = ____

# Print unemp_fuel_stats
print(unemp_fuel_stats)
Edit and Run Code