Reindexing a specific level of a MultiIndex dataframe

前端 未结 1 1983
情深已故
情深已故 2020-12-07 02:02

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
im         


        
相关标签:
1条回答
  • 2020-12-07 02:59

    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()
    
    0 讨论(0)
提交回复
热议问题