O'Reilly logo

Learning pandas - Second Edition 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

Re-indexing a Series

Re-indexing in pandas is a process that makes the data in a Series conform to a set of labels. It is used by pandas to perform much of the alignment process and is hence a fundamental operation.

Re-indexing achieves several things:

  • Re-ordering 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)

Re-indexing can be as simple as simply assigning a new index to the .index property of a Series. The following demonstrates changing the index of a Series in this manner:

The number of ...

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