Table Of Contents


Enter search terms or a module, class or function name.


MultiIndex.slice_locs(start=None, end=None, step=None, kind=None)[source]

For an ordered MultiIndex, compute the slice locations for input labels.

The input labels can be tuples representing partial levels, e.g. for a MultiIndex with 3 levels, you can pass a single value (corresponding to the first level), or a 1-, 2-, or 3-tuple.


start : label or tuple, default None

If None, defaults to the beginning

end : label or tuple

If None, defaults to the end

step : int or None

Slice step

kind : string, optional, defaults None


(start, end) : (int, int)

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.


This method only works if the MultiIndex is properly lex-sorted. So, if only the first 2 levels of a 3-level MultiIndex are lexsorted, you can only pass two levels to .slice_locs.


>>> mi = pd.MultiIndex.from_arrays([list('abbd'), list('deff')],
...                                names=['A', 'B'])

Get the slice locations from the beginning of ‘b’ in the first level until the end of the multiindex:

>>> mi.slice_locs(start='b')
(1, 4)

Like above, but stop at the end of ‘b’ in the first level and ‘f’ in the second level:

>>> mi.slice_locs(start='b', end=('b', 'f'))
(1, 3)
Scroll To Top