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.
This exercise is part of the course
Introduction to Statistics in Python
Exercise instructions
- Import
numpy
with the aliasnp
. - Subset
food_consumption
to get the rows where thecountry
is'USA'
. - Calculate the mean of food
consumption
in theusa_consumption
DataFrame, which is already created for you. - Calculate the median of food
consumption
in theusa_consumption
DataFrame.
Hands-on interactive exercise
Have a go at this exercise by completing this sample 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(____)