Index.get_indexer(target, method=None, limit=None, tolerance=None)[source]#

Compute indexer and mask for new index given the current index.

The indexer should be then used as an input to ndarray.take to align the current data to the new index.

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] - target) <= tolerance.


Integers from 0 to n - 1 indicating that the index at these positions matches the corresponding target values. Missing values in the target are marked by -1.


>>> import cudf
>>> index = cudf.Index(['c', 'a', 'b'])
>>> index
Index(['c', 'a', 'b'], dtype='object')
>>> index.get_indexer(['a', 'b', 'x'])
array([ 1,  2, -1], dtype=int32)