W3cubDocs

/pandas 0.25

pandas.MultiIndex.get_level_values

MultiIndex.get_level_values(self, level) [source]

Return vector of label values for requested level, equal to the length of the index.

Parameters:
level : int or str

level is either the integer position of the level in the MultiIndex, or the name of the level.

Returns:
values : Index

Values is a level of this MultiIndex converted to a single Index (or subclass thereof).

Examples

Create a MultiIndex:

>>> mi = pd.MultiIndex.from_arrays((list('abc'), list('def')))
>>> mi.names = ['level_1', 'level_2']

Get level values by supplying level as either integer or name:

>>> mi.get_level_values(0)
Index(['a', 'b', 'c'], dtype='object', name='level_1')
>>> mi.get_level_values('level_2')
Index(['d', 'e', 'f'], dtype='object', name='level_2')

© 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.get_level_values.html