pandas.MultiIndex.reorder_levels
- MultiIndex.reorder_levels(order)[source]
-
Rearrange levels using input order. May not drop or duplicate levels.
- Parameters
-
- order:list of int or list of str
-
List representing new level order. Reference level by number (position) or by key (label).
- Returns
-
- MultiIndex
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'])
© 2008–2021, 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/1.3.4/reference/api/pandas.MultiIndex.reorder_levels.html