pandas.Index.slice_indexer

Index.slice_indexer(start=None, end=None, step=None, kind=None)[source]

Compute the slice indexer for input labels and step.

Index needs to be ordered and unique.

Parameters
start:label, default None

If None, defaults to the beginning.

end:label, default None

If None, defaults to the end.

step:int, default None
kind:str, default None
Returns
indexer:slice
Raises
KeyError:If key does not exist, or key is not unique and index is

not ordered.

Notes

This function assumes that the data is sorted, so use at your own peril

Examples

This is a method on all index types. For example you can do:

>>> idx = pd.Index(list('abcd'))
>>> idx.slice_indexer(start='b', end='c')
slice(1, 3, None)
>>> idx = pd.MultiIndex.from_arrays([list('abcd'), list('efgh')])
>>> idx.slice_indexer(start='b', end=('c', 'g'))
slice(1, 3, None)

© 2008–2021, AQR Capital Management, LLC, Lambda Foundry, Inc. and PyData Development Team
Licensed under the 3-clause BSD License.
https://pandas.pydata.org/pandas-docs/version/1.3.4/reference/api/pandas.Index.slice_indexer.html