Movatterモバイル変換


[0]ホーム

URL:


Skip to main content
Ctrl+K

pandas.Index.get_indexer#

finalIndex.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 thecurrent data to the new index.

Parameters:
targetIndex
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. Tieddistances are broken by preferring the larger index value.

limitint, optional

Maximum number of consecutive labels intarget to match forinexact matches.

toleranceoptional

Maximum distance between original and new labels for inexactmatches. The values of the index at the matching locations mustsatisfy the equationabs(index[indexer]-target)<=tolerance.

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

Returns:
np.ndarray[np.intp]

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

Notes

Returns -1 for unmatched values, for further explanation see theexample below.

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 inindexandx is marked by -1, as it is not inindex.


[8]ページ先頭

©2009-2025 Movatter.jp