Named aggregations
You've seen how .groupby()
and .agg()
can be combined to show summaries across categories. Sometimes, it's helpful to name new columns when aggregating so that it's clear in the code output what aggregations are being applied and where.
Your task is to create a DataFrame called continent_summary
which shows a row for each continent. The DataFrame columns will contain the mean unemployment rate for each continent in 2021 as well as the standard deviation of the 2021 employment rate. And of course, you'll rename the columns so that their contents are clear!
The unemployment
DataFrame is available, and pandas
has been imported as pd
.
This exercise is part of the course
Exploratory Data Analysis in Python
Exercise instructions
- Create a column called
mean_rate_2021
which shows the mean 2021 unemployment rate for each continent. - Create a column called
std_rate_2021
which shows the standard deviation of the 2021 unemployment rate for each continent.
Hands-on interactive exercise
Have a go at this exercise by completing this sample code.
continent_summary = unemployment.groupby("continent").agg(
# Create the mean_rate_2021 column
____=____,
# Create the std_rate_2021 column
____=____
)
print(continent_summary)