Reindexing a Series
Reindexing in pandas is a process that makes the data in a Series
or DataFrame
match a given set of labels. This is core to the functionality of pandas as it enables label alignment across multiple objects, which may originally have different indexing schemes.
This process of performing a reindex includes the following steps:
- Reordering existing data to match a set of labels.
- Inserting
NaN
markers where no data exists for a label. - Possibly, filling missing data for a label using some type of logic (defaulting to adding
NaN
values).
Here 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 ...
Get Learning pandas 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.