pandas.Series.swaplevel

Series.swaplevel(self, i=-2, j=-1, copy=True)[source]

Swap levels i and j in a MultiIndex.

Default is to swap the two innermost levels of the index.

Parameters
i, jint, str

Level of the indices to be swapped. Can pass level name as string.

copybool, default True

Whether to copy underlying data.

Returns
Series

Series with levels swapped in MultiIndex.