MultiIndex.get_loc_level(self, key, level=0, drop_level=True)[source]

Get both the location for the requested label(s) and the resulting sliced index.

keylabel or sequence of labels
levelint/level name or list thereof, optional
drop_levelbool, default True

if False, the resulting index will not drop any level.

locA 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


Get location for a label or a tuple of labels.


Get location for a label/slice/list/mask or a sequence of such.


>>> 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], dtype=bool),
Index(['b'], dtype='object', name='A'))
>>> mi.get_loc_level(['b', 'e'])
(1, None)
Scroll To Top