pandas 1.4.2

NotesParametersReturnsBackRef
slice_locs(self, start=None, end=None, step=None, kind=<no_default>) -> 'tuple[int, int]'

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.

Notes

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

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
deprecated

Returns

(start, end) : (int, int)

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

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.

Examples

This example is valid syntax, but we were not able to check execution
>>> 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:

This example is valid syntax, but we were not able to check execution
>>> 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:

This example is valid syntax, but we were not able to check execution
>>> mi.slice_locs(start='b', end=('b', 'f'))
(1, 3)
See :

Back References

The following pages refer to to this document either explicitly or contain code examples using this.

pandas.core.indexes.multi.MultiIndex.get_loc pandas.core.indexes.multi.MultiIndex.get_locs

Local connectivity graph

Hover to see nodes names; edges to Self not shown, Caped at 50 nodes.

Using a canvas is more power efficient and can get hundred of nodes ; but does not allow hyperlinks; , arrows or text (beyond on hover)

SVG is more flexible but power hungry; and does not scale well to 50 + nodes.

All aboves nodes referred to, (or are referred from) current nodes; Edges from Self to other have been omitted (or all nodes would be connected to the central node "self" which is not useful). Nodes are colored by the library they belong to, and scaled with the number of references pointing them


File: /pandas/core/indexes/multi.py#2677
type: <class 'function'>
Commit: