A DataFrame can be reindexed using the .reindex() method. Reindexing makes the DataFrame conform to the new index, aligning data from the old index with the new and filling in NaN where alignment fails.
This code demonstrates re-indexing the sp500 to the three specified index labels.
This process creates a new DataFrame with specified rows. If a row is not found for a specific value, then NaN values are inserted as is seen with the 'FOO' label. This method is actually a good technique of filtering out data based on the index labels.
Reindexing can also be done upon columns, as demonstrated by the following code for ...