Session Ready
Exercise

Mean and median

In this chapter, you'll be working with the 2018 Food Carbon Footprint Index from nu3. The food_consumption dataset contains information about the kilograms of food consumed per person per year in each country in each food category (consumption) as well as information about the carbon footprint of that food category (co2_emissions) measured in kilograms of carbon dioxide, or CO\(_2\), per person per year in each country.

In this exercise, you'll compute measures of center to compare food consumption in the US and Belgium using your pandas and numpy skills.

pandas is imported as pd for you and food_consumption is pre-loaded.

Instructions 1/2
undefined XP
  • 1
    • Import numpy with the alias np.
    • Create two DataFrames: one that holds the rows of food_consumption for 'Belgium' and another that holds rows for 'USA'. Call these be_consumption and usa_consumption.
    • Calculate the mean and median of kilograms of food consumed per person per year for both countries.
    • 2
      • Subset food_consumption for rows with data about Belgium and the USA.
      • Group the subsetted data by country and select only the consumption column.
      • Calculate the mean and median of the kilograms of food consumed per person per year in each country using .agg().