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

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


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