pandas.MultiIndex.get_loc_level
- MultiIndex.get_loc_level(key, level=0, drop_level=True)[source]
-
Get location and sliced index for requested label(s)/level(s).
- Parameters
-
- key:label or sequence of labels
- level:int/level name or list thereof, optional
- drop_level:bool, default True
-
If
False
, the resulting index will not drop any level.
- Returns
-
- loc:A 2-tuple where the elements are:
-
Element 0: int, slice object or boolean array Element 1: The resulting sliced multiindex/index. If the key contains all levels, this will be
None
.
See also
MultiIndex.get_loc
-
Get location for a label or a tuple of labels.
MultiIndex.get_locs
-
Get location for a label/slice/list/mask or a sequence of such.
Examples
>>> mi = pd.MultiIndex.from_arrays([list('abb'), list('def')], ... names=['A', 'B'])
>>> mi.get_loc_level('b') (slice(1, 3, None), Index(['e', 'f'], dtype='object', name='B'))
>>> mi.get_loc_level('e', level='B') (array([False, True, False]), Index(['b'], dtype='object', name='A'))
>>> mi.get_loc_level(['b', 'e']) (1, None)
© 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.get_loc_level.html