Reindexing A Specific Level Of A Multiindex Dataframe
I have a DataFrame with two indices and would like to reindex it by one of the indices. from pandas_datareader import data import matplotlib.pyplot as plt import pandas as pd # In
Solution 1:
If you're looking to reindex on a certain level, then reindex accepts a level argument you can pass -
adj_close.reindex(all_weekdays, level=0)
When passing a level argument, you cannot pass a method argument at the same time (reindex throws a TypeError), so you can chain a ffill call after -
adj_close.reindex(all_weekdays, level=0).ffill()
Post a Comment for "Reindexing A Specific Level Of A Multiindex Dataframe"