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. NumPy, which is imported as np, has many different summary statistics functions, including: np.min, np.max, np.mean, and np.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

  • Import numpy with the alias np.
  • Get the min, max, mean, and median of weekly_sales for each store type using .groupby() and .agg(). Store this as sales_stats. Make sure to use numpy functions!
  • 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.

# Import numpy with the alias np
____

# 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