Retrieving values in a Series by label or position
Values in a Series
can be retrieved in two general ways: by index label or by 0-based position. Pandas provides you with a number of ways to perform either of these lookups. Let's examine a few of the common techniques.
Lookup by label using the [] operator and the .ix[] property
An implicit label lookup is performed using the []
operator. This operator normally looks up values based upon the given index labels.
Let's start by using the following Series
:

A single value can be looked up using just the index label of the desired item:

Multiple items can be retrieved at once using a list of index labels:

We can also look up values using integers that represent positions:

This works purely because the index is not using integer labels. If integers are passed to []
, and the index has integer values, then the lookup is performed by matching the values passed in to the values of the integer labels.
This can be demonstrated using the following Series
:

The...