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

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

method{None, ‘pad’/’fill’, ‘backfill’/’bfill’, ‘nearest’}, optional
  • default: exact matches only.

  • pad / ffill: find the PREVIOUS index value if no exact match.

  • backfill / bfill: use NEXT index value if no exact match.

  • nearest: use the NEAREST index value if no exact match. Tied distances are broken by preferring the larger index value.

toleranceint or float, optional

Maximum distance from index value for inexact matches. The value of the index at the matching location must satisfy the equation abs(index[loc] - key) <= tolerance.

int or slice or boolean mask
  • If result is unique, return integer index

  • If index is monotonic, loc is returned as a slice object

  • Otherwise, a boolean mask is returned


>>> unique_index = cudf.Index(list('abc'))
>>> unique_index.get_loc('b')
>>> monotonic_index = cudf.Index(list('abbc'))
>>> monotonic_index.get_loc('b')
slice(1, 3, None)
>>> non_monotonic_index = cudf.Index(list('abcb'))
>>> non_monotonic_index.get_loc('b')
array([False,  True, False,  True])
>>> numeric_unique_index = cudf.Index([1, 2, 3])
>>> numeric_unique_index.get_loc(3)