pandas.IntervalIndex.get_loc#
- IntervalIndex.get_loc(key)[source]#
Get integer location, slice or boolean mask for requested label.
The get_loc method is used to retrieve the integer index, a slice for slicing objects, or a boolean mask indicating the presence of the label in the IntervalIndex.
- Parameters:
- keylabel
The value or range to find in the IntervalIndex.
- Returns:
- int if unique index, slice if monotonic index, else mask
The position or positions found. This could be a single number, a range, or an array of true/false values indicating the position(s) of the label.
See also
IntervalIndex.get_indexer_non_unique
Compute indexer and mask for new index given the current index.
Index.get_loc
Similar method in the base Index class.
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