def get_loc_level(self, key, level=<NUM_LIT:0>, drop_level=True):
def maybe_droplevels(indexer, levels, drop_level):<EOL><INDENT>if not drop_level:<EOL><INDENT>return self[indexer]<EOL><DEDENT>orig_index = new_index = self[indexer]<EOL>levels = [self._get_level_number(i) for i in levels]<EOL>for i in sorted(levels, reverse=True):<EOL><INDENT>try:<EOL><INDENT>new_index = new_index.droplevel(i)<EOL><DEDENT>except ValueError:<EOL><INDENT>return orig_index<EOL><DEDENT><DEDENT>return new_index<EOL><DEDENT>if isinstance(level, (tuple, list)):<EOL><INDENT>if len(key) != len(level):<EOL><INDENT>raise AssertionError('<STR_LIT>'<EOL>'<STR_LIT>')<EOL><DEDENT>result = None<EOL>for lev, k in zip(level, key):<EOL><INDENT>loc, new_index = self.get_loc_level(k, level=lev)<EOL>if isinstance(loc, slice):<EOL><INDENT>mask = np.zeros(len(self), dtype=bool)<EOL>mask[loc] = True<EOL>loc = mask<EOL><DEDENT>result = loc if result is None else result & loc<EOL><DEDENT>return result, maybe_droplevels(result, level, drop_level)<EOL><DEDENT>level = self._get_level_number(level)<EOL>if isinstance(key, list):<EOL><INDENT>key = tuple(key)<EOL><DEDENT>if isinstance(key, tuple) and level == <NUM_LIT:0>:<EOL><INDENT>try:<EOL><INDENT>if key in self.levels[<NUM_LIT:0>]:<EOL><INDENT>indexer = self._get_level_indexer(key, level=level)<EOL>new_index = maybe_droplevels(indexer, [<NUM_LIT:0>], drop_level)<EOL>return indexer, new_index<EOL><DEDENT><DEDENT>except TypeError:<EOL><INDENT>pass<EOL><DEDENT>if not any(isinstance(k, slice) for k in key):<EOL><INDENT>def partial_selection(key, indexer=None):<EOL><INDENT>if indexer is None:<EOL><INDENT>indexer = self.get_loc(key)<EOL><DEDENT>ilevels = [i for i in range(len(key))<EOL>if key[i] != slice(None, None)]<EOL>return indexer, maybe_droplevels(indexer, ilevels,<EOL>drop_level)<EOL><DEDENT>if len(key) == self.nlevels and self.is_unique:<EOL><INDENT>return (self._engine.get_loc(key), None)<EOL><DEDENT>else:<EOL><INDENT>return partial_selection(key)<EOL><DEDENT><DEDENT>else:<EOL><INDENT>indexer = None<EOL>for i, k in enumerate(key):<EOL><INDENT>if not isinstance(k, slice):<EOL><INDENT>k = self._get_level_indexer(k, level=i)<EOL>if isinstance(k, slice):<EOL><INDENT>if k.start == <NUM_LIT:0> and k.stop == len(self):<EOL><INDENT>k = slice(None, None)<EOL><DEDENT><DEDENT>else:<EOL><INDENT>k_index = k<EOL><DEDENT><DEDENT>if isinstance(k, slice):<EOL><INDENT>if k == slice(None, None):<EOL><INDENT>continue<EOL><DEDENT>else:<EOL><INDENT>raise TypeError(key)<EOL><DEDENT><DEDENT>if indexer is None:<EOL><INDENT>indexer = k_index<EOL><DEDENT>else:  <EOL><INDENT>indexer &= k_index<EOL><DEDENT><DEDENT>if indexer is None:<EOL><INDENT>indexer = slice(None, None)<EOL><DEDENT>ilevels = [i for i in range(len(key))<EOL>if key[i] != slice(None, None)]<EOL>return indexer, maybe_droplevels(indexer, ilevels, drop_level)<EOL><DEDENT><DEDENT>else:<EOL><INDENT>indexer = self._get_level_indexer(key, level=level)<EOL>return indexer, maybe_droplevels(indexer, [level], drop_level)<EOL><DEDENT>
Get both the location for the requested label(s) and the
resulting sliced index.

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``.

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], dtype=bool),
Index(['b'], dtype='object', name='A'))

>>> mi.get_loc_level(['b', 'e'])
(1, 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.