pandas.IntervalIndex.get_indexer

IntervalIndex.get_indexer(self, target: ~AnyArrayLike, method: Union[str, NoneType] = None, limit: Union[int, NoneType] = None, tolerance: Union[Any, NoneType] = None) → numpy.ndarray[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.

Parameters
targetIntervalIndex or list of Intervals
method{None, ‘pad’/’ffill’, ‘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.

limitint, optional

Maximum number of consecutive labels in target to match for inexact matches.

toleranceoptional

Maximum distance between original and new labels for inexact matches. The values of the index at the matching locations most satisfy the equation abs(index[indexer] - target) <= tolerance.

Tolerance may be a scalar value, which applies the same tolerance to all values, or list-like, which applies variable tolerance per element. List-like includes list, tuple, array, Series, and must be the same size as the index and its dtype must exactly match the index’s type.

New in version 0.21.0: (list-like tolerance)

Returns
indexerndarray of int

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.

Raises
NotImplementedError

If any method argument other than the default of None is specified as these are not yet implemented.

Examples

>>> index = pd.Index(['c', 'a', 'b'])
>>> index.get_indexer(['a', 'b', 'x'])
array([ 1,  2, -1])

Notice that the return value is an array of locations in index and x is marked by -1, as it is not in index.