Use DataFrame.reorder_levels : df = pd.DataFrame({ 'A':list('abcdef'), 'B':[4,5,4,5,5 ,4], 'C':[7,8,9,4,2,3], 'D':[1,3,5,7,1,0], 'E':[5,3,6,9,2,4], ...
Swap level i with level j. Calling this method does not change the ordering of the values. Parameters. iint, str, default -2.
Your columns are a MultiIndex. You need to reassign the DataFrame's columns with a new MultiIndex created from swapping levels of the ...
Swap levels i and j in a MultiIndex on a particular axis. Parameters. i, jint or str. Levels of the indices to be swapped. Can pass level name as string ...
Assuming they have the same label, you can use reindex with level=1 : df A B 1 2 1 2 0 a b c d df.reindex([2, 1], level=1, axis=1) ...
Swap level i with level j. reorder_levels (order). Rearrange levels using input order. remove_unused_levels (). Create new MultiIndex from current that removes ...
Pandas MultiIndex.swaplevel() function is used to swap levels of the
Rearrange index levels using input order. May not drop or duplicate levels. Parameters. orderlist of int or list of str. List representing new level order ...
Pandas MultiIndex.reorder_levels() function is used to rearrange levels using input order. It may not drop or duplicate levels. The function take ...
with the index column labels ['E', 'Theta', 'Phi'] , and we want to change the order of the levels.