Get startedGet started for free

Subsetting pivot tables

A pivot table is just a DataFrame with sorted indexes, so the techniques you have learned already can be used to subset them. In particular, the .loc[] + slicing combination is often helpful.

pandas is loaded as pd. temp_by_country_city_vs_year is available.

This exercise is part of the course

Data Manipulation with pandas

View Course

Exercise instructions

Use .loc[] on temp_by_country_city_vs_year to take subsets.

  • From Egypt to India.
  • From Egypt, Cairo to India, Delhi.
  • From Egypt, Cairo to India, Delhi, and 2005 to 2010.

Hands-on interactive exercise

Have a go at this exercise by completing this sample code.

# Subset for Egypt to India
____

# Subset for Egypt, Cairo to India, Delhi
____

# Subset for Egypt, Cairo to India, Delhi, and 2005 to 2010
____
Edit and Run Code