Working with Indexes
Having covered creating various types of pandas indexes, let's now examine several common patterns of use for these indexes. Specifically, we will examine:
- Creating and using an index with a Series or DataFrame
- Means of selecting values with an index
- Moving data to and from the index
- Reindexing a pandas object
Creating and using an index with a Series or DataFrame
Indexes can either be created explicitly or you can let pandas create them implicitly. Explicit creation takes place when you assign the index using the index
parameter of a constructor.
The following code demonstrates by first creating a DatetimeIndex
independently.

You can use this index on its own or associate it with a Series
or DataFrame
. This code creates a DataFrame
utilizing the index.

An index can also be directly assigned to an existing DataFrame
or Series by setting the .index
property.

Selecting values using an index
Values can be looked up using an index using the []
operator or by using the following property...