MultiIndex.set_levels(self, levels, level=None, inplace=False, verify_integrity=True)
[source]
Set new levels on MultiIndex. Defaults to returning new index.
Parameters: |
|
---|---|
Returns: |
|
>>> idx = pd.MultiIndex.from_tuples([(1, 'one'), (1, 'two'), (2, 'one'), (2, 'two')], names=['foo', 'bar']) >>> idx.set_levels([['a', 'b'], [1, 2]]) MultiIndex([('a', 1), ('a', 2), ('b', 1), ('b', 2)], names=['foo', 'bar']) >>> idx.set_levels(['a', 'b'], level=0) MultiIndex([('a', 'one'), ('a', 'two'), ('b', 'one'), ('b', 'two')], names=['foo', 'bar']) >>> idx.set_levels(['a', 'b'], level='bar') MultiIndex([(1, 'a'), (1, 'b'), (2, 'a'), (2, 'b')], names=['foo', 'bar']) >>> idx.set_levels([['a', 'b'], [1, 2]], level=[0, 1]) MultiIndex([('a', 1), ('a', 2), ('b', 1), ('b', 2)], names=['foo', 'bar'])
© 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.set_levels.html