MultiIndex.
reorder_levels
Rearrange levels using input order. May not drop or duplicate levels.
List representing new level order. Reference level by number (position) or by key (label).
Examples
>>> mi = pd.MultiIndex.from_arrays([[1, 2], [3, 4]], names=['x', 'y']) >>> mi MultiIndex([(1, 3), (2, 4)], names=['x', 'y'])
>>> mi.reorder_levels(order=[1, 0]) MultiIndex([(3, 1), (4, 2)], names=['y', 'x'])
>>> mi.reorder_levels(order=['y', 'x']) MultiIndex([(3, 1), (4, 2)], names=['y', 'x'])