cudf.IntervalIndex.get_loc#

IntervalIndex.get_loc(key) int | slice | ndarray[source]#

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

Parameters:
keylabel
Returns:
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

Examples

>>> import cudf
>>> unique_index = cudf.Index(list('abc'))
>>> unique_index.get_loc('b')
1
>>> 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)
2

MultiIndex

>>> multi_index = cudf.MultiIndex.from_tuples([('a', 'd'), ('b', 'e'), ('b', 'f')])
>>> multi_index
MultiIndex([('a', 'd'),
            ('b', 'e'),
            ('b', 'f')],
        )
>>> multi_index.get_loc('b')
slice(1, 3, None)
>>> multi_index.get_loc(('b', 'e'))
1