pandas.IntervalIndex.get_loc#

IntervalIndex.get_loc(key, method=None, tolerance=None)[source]#

Get integer location, slice or boolean mask for requested label.

Parameters
keylabel
method{None}, optional
  • default: matches where the label is within an interval only.

Deprecated since version 1.4.

Returns
int if unique index, slice if monotonic index, else mask

Examples

>>> i1, i2 = pd.Interval(0, 1), pd.Interval(1, 2)
>>> index = pd.IntervalIndex([i1, i2])
>>> index.get_loc(1)
0

You can also supply a point inside an interval.

>>> index.get_loc(1.5)
1

If a label is in several intervals, you get the locations of all the relevant intervals.

>>> i3 = pd.Interval(0, 2)
>>> overlapping_index = pd.IntervalIndex([i1, i2, i3])
>>> overlapping_index.get_loc(0.5)
array([ True, False,  True])

Only exact matches will be returned if an interval is provided.

>>> index.get_loc(pd.Interval(0, 1))
0