CommencerCommencer gratuitement

Mean and median

In this chapter, you'll be working with the food_consumption dataset from 2018 Food Carbon Footprint Index by nu3. The food_consumption dataset contains the number of kilograms of food consumed per person per year in each country and food category (consumption), and its carbon footprint (co2_emissions) measured in kilograms of carbon dioxide, or CO2.

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.

Cet exercice fait partie du cours

Introduction to Statistics in Python

Afficher le cours

Instructions

  • Import numpy with the alias np.
  • Subset food_consumption to get the rows where the country is 'USA'.
  • Calculate the mean of food consumption in the usa_consumption DataFrame, which is already created for you.
  • Calculate the median of food consumption in the usa_consumption DataFrame.

Exercice interactif pratique

Essayez cet exercice en complétant cet exemple de code.

# Import numpy with alias np
____

# Subset country for USA: usa_consumption
usa_consumption = ____

# Calculate mean consumption in USA
print(____)

# Calculate median consumption in USA
print(____)
Modifier et exécuter le code