Book Image

Mastering Pandas for Finance

By : Michael Heydt
Book Image

Mastering Pandas for Finance

By: Michael Heydt

Overview of this book

Table of Contents (16 chapters)
Mastering pandas for Finance
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

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 the values able to be accessed via the character labels in the new index:

In [60]:
   np.random.seed(1)
   s = pd.Series(np.random.randn(5))
   s

Out[60]:
   0    1.624345
   1   -0.611756
   2   -0.528172
   3   -1.072969
   4    0.865408
   dtype...