pandas.MultiIndex.get_loc — pandas 3.0.0rc0+34.g04a554c9f1 documentation (original) (raw)
MultiIndex.get_loc(key)[source]#
Get location for a label or a tuple of labels. The location is returned as an integer/slice or boolean mask.
This method returns the integer location, slice object, or boolean mask corresponding to the specified key, which can be a single label or a tuple of labels. The key represents a position in the MultiIndex, and the location indicates where the key is found within the index.
Parameters:
keylabel or tuple of labels (one for each level)
A label or tuple of labels that correspond to the levels of the MultiIndex. The key must match the structure of the MultiIndex.
Returns:
int, slice object or boolean mask
If the key is past the lexsort depth, the return may be a boolean mask array, otherwise it is always a slice or int.
See also
The get_loc method for (single-level) index.
MultiIndex.slice_locs
Get slice location given start label(s) and end label(s).
Get location for a label/slice/list/mask or a sequence of such.
Notes
The key cannot be a slice, list of same-level labels, a boolean mask, or a sequence of such. If you want to use those, useMultiIndex.get_locs() instead.
Examples
mi = pd.MultiIndex.from_arrays([list("abb"), list("def")])
mi.get_loc("b") slice(1, 3, None)
mi.get_loc(("b", "e")) 1