Aan de slagGa gratis aan de slag

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.

Deze oefening maakt deel uit van de cursus

Exploratory Data Analysis in Python

Cursus bekijken

Oefeninstructies

  • 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.

Praktische interactieve oefening

Probeer deze oefening eens door deze voorbeeldcode in te vullen.

continent_summary = unemployment.groupby("continent").agg(
    # Create the mean_rate_2021 column
    ____=____,
    # Create the std_rate_2021 column
    ____=____
)
print(continent_summary)
Code bewerken en uitvoeren