1. सीखें
  2. /
  3. पाठ्यक्रम
  4. /
  5. Data Manipulation with pandas

Connected

अभ्यास

Subsetting with .loc[]

The killer feature for indexes is .loc[]: a subsetting method that accepts index values. When you pass it a single argument, it will take a subset of rows.

The code for subsetting using .loc[] can be easier to read than standard square bracket subsetting, which can make your code less burdensome to maintain.

pandas is loaded as pd. temperatures and temperatures_ind are available; the latter is indexed by city.

निर्देश

100 XP
  • Create a list called cities that contains "London" and "Paris".
  • Use [] subsetting to filter temperatures for rows where the city column takes a value in the cities list.
  • Use .loc[] subsetting to filter temperatures_ind for rows where the city is in the cities list.