Converting a pandas MultiIndex DataFrame from rows-wise to column-wise

后端 未结 1 1681
囚心锁ツ
囚心锁ツ 2021-02-15 17:04

I\'m working in zipline and pandas and have converted a pandas.Panel to a pandas.DataFrame using the to_frame() method. This is the result

相关标签:
1条回答
  • 2021-02-15 17:32

    Because you have a MultiIndex in place already, stack and unstack are what you want to use to move rows to cols and vice versa. That being said, unstack should do exactly what you want to accomplish. If you have a DataFrame df then df2 = df.unstack('minor') should do the trick. Or more simply, since by default stack/unstack use the innermost level, df2 = df.unstack().

    0 讨论(0)
提交回复
热议问题