Table Of Contents

Search

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

pandas.MultiIndex.get_major_bounds

MultiIndex.get_major_bounds(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.

Parameters:

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

Returns:

(start, end) : (int, int)

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.

Notes

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.

Examples

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