O'Reilly logo

Learning pandas by Michael Heydt

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Looking up values in Series

Values in a Series object can be retrieved using the [] operator and passing either a single index label or a list of index labels. The following code retrieves the value associated with the index label 'a' of the s3 series defined earlier:

In [28]:
   # single item lookup
   s3['a']

Out[28]:
   1

Accessing this Series using an integer value will perform a zero-based position lookup of the value:

In [29]:
   # lookup by position since the index is not an integer
   s3[1]

Out[29]:
   2

This is because pandas determines that the specified value is an integer and that the index is not an integer-based index. Given this, pandas decides to perform a lookup by position and not by index label.

To retrieve multiple items, you can pass a ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required