MultiIndex.swaplevel(self, i=-2, j=-1)
[source]
Swap level i with level j.
Calling this method does not change the ordering of the values.
Parameters: |
|
---|---|
Returns: |
Changed in version 0.18.1: The indexes |
See also
Series.swaplevel
Dataframe.swaplevel
>>> 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')], )
© 2008–2012, AQR Capital Management, LLC, Lambda Foundry, Inc. and PyData Development Team
Licensed under the 3-clause BSD License.
https://pandas.pydata.org/pandas-docs/version/0.25.0/reference/api/pandas.MultiIndex.swaplevel.html