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
Exercise instructions
- Import
numpy
with the aliasnp
. - Get the min, max, mean, and median of
weekly_sales
for each store type using.groupby()
and.agg()
. Store this assales_stats
. Make sure to usenumpy
functions! - Get the min, max, mean, and median of
unemployment
andfuel_price_usd_per_l
for each store type. Store this asunemp_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)