MultiIndex.
swaplevel
Swap level i with level j.
Calling this method does not change the ordering of the values.
First level of index to be swapped. Can pass level name as string. Type of parameters can be mixed.
Second level of index to be swapped. Can pass level name as string. Type of parameters can be mixed.
A new MultiIndex.
See also
Series.swaplevel
Swap levels i and j in a MultiIndex.
Dataframe.swaplevel
Swap levels i and j in a MultiIndex on a particular axis.
Examples
>>> mi = pd.MultiIndex(levels=[['a', 'b'], ['bb', 'aa']], ... codes=[[0, 0, 1, 1], [0, 1, 0, 1]]) >>> mi MultiIndex([('a', 'bb'), ('a', 'aa'), ('b', 'bb'), ('b', 'aa')], ) >>> mi.swaplevel(0, 1) MultiIndex([('bb', 'a'), ('aa', 'a'), ('bb', 'b'), ('aa', 'b')], )