pandas.DataFrame.swaplevel

DataFrame.swaplevel(i=- 2, j=- 1, axis=0)[source]

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.

axis{0 or ‘index’, 1 or ‘columns’}, default 0

The axis to swap levels on. 0 or ‘index’ for row-wise, 1 or ‘columns’ for column-wise.

Returns
DataFrame