Reindexing the Series and DataFrame objects

Reindexing in pandas is a process that makes the data present in a Series or DataFrame match with a given set of labels along a particular axis. This is core to the functionalities of pandas as it enables label alignment across multiple objects.

The process of performing a reindex does the following:

  • Reorders existing data to match a set of labels
  • Inserts NaN markers where no data exists for a label
  • Fills missing data for a label using a type of logic (defaulting to adding NaNs)

The following is a simple example of reindexing a Series. The following Series has an index with numerical values, and the index is modified to be alphabetic by simply assigning a list of characters to the .index property, making ...

Get Mastering pandas for Finance now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.