Indexing Operations (.iloc)

Learn how to retrieve and manipulate records based on a positional index.

The iloc attribute

The series also supports indexing off the iloc attribute. This attribute is analogous to loc but with a few differences. We pull out items by index position when we slice off this attribute. The iloc attribute supports indexing with the following:

  • A scalar index position (an integer).
  • A list of index positions.
  • A slice of positions (half-open interval so it doesn’t include stop value).
  • A NumPy array (or Python list) of boolean values.
  • A function that accepts a Series and returns one of the above.

In the examples below, we’ll pull out the first and last values by slicing off of iloc with a scalar. Note that because index positions are unique, we’ll always get the scalar value when indexing with iloc at a position:

Get hands-on with 1400+ tech skills courses.