MulaiMulai sekarang secara gratis

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.

Latihan ini adalah bagian dari kursus

Introduction to Statistics in Python

Lihat Kursus

Petunjuk latihan

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

Latihan interaktif praktis

Cobalah latihan ini dengan menyelesaikan kode contoh berikut.

# 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(____)
Edit dan Jalankan Kode