1. Learn
  2. /
  3. Courses
  4. /
  5. Data Manipulation with pandas

Connected

Exercise

Subsetting by row/column number

The most common ways to subset rows are the ways we've previously discussed: using a Boolean condition or by index labels. However, it is also occasionally useful to pass row numbers.

This is done using .iloc[], and like .loc[], it can take two arguments to let you subset by rows and columns.

pandas is loaded as pd. temperatures (without an index) is available.

Instructions

100 XP

Use .iloc[] on temperatures to take subsets.

  • Get the 23rd row, 2nd column (index positions 22 and 1).
  • Get the first 5 rows (index positions 0 to 5).
  • Get all rows, columns 3 and 4 (index positions 2 to 4).
  • Get the first 5 rows, columns 3 and 4.