Skip to content Skip to sidebar Skip to footer

Converting A Pandas MultiIndex DataFrame From Rows-wise To Column-wise

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 resulting pandas.DataFrame which as you can see i

Solution 1:

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().


Post a Comment for "Converting A Pandas MultiIndex DataFrame From Rows-wise To Column-wise"