MCPcopy
hub / github.com/pandas-dev/pandas / get_indexer

Method get_indexer

pandas/core/indexes/base.py:3657–3796  ·  view source on GitHub ↗

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 ---------- target : Index An iterable containing the value

(
        self,
        target,
        method: ReindexMethod | None = None,
        limit: int | None = None,
        tolerance=None,
    )

Source from the content-addressed store, hash-verified

3655
3656 @final
3657 def get_indexer(
3658 self,
3659 target,
3660 method: ReindexMethod | None = None,
3661 limit: int | None = None,
3662 tolerance=None,
3663 ) -> npt.NDArray[np.intp]:
3664 """
3665 Compute indexer and mask for new index given the current index.
3666
3667 The indexer should be then used as an input to ndarray.take to align the
3668 current data to the new index.
3669
3670 Parameters
3671 ----------
3672 target : Index
3673 An iterable containing the values to be used for computing indexer.
3674 method : {None, 'pad'/'ffill', 'backfill'/'bfill', 'nearest'}, optional
3675 * default: exact matches only.
3676 * pad / ffill: find the PREVIOUS index value if no exact match.
3677 * backfill / bfill: use NEXT index value if no exact match
3678 * nearest: use the NEAREST index value if no exact match. Tied
3679 distances are broken by preferring the larger index value.
3680 limit : int, optional
3681 Maximum number of consecutive labels in ``target`` to match for
3682 inexact matches.
3683 tolerance : optional
3684 Maximum distance between original and new labels for inexact
3685 matches. The values of the index at the matching locations must
3686 satisfy the equation ``abs(index[indexer] - target) <= tolerance``.
3687
3688 Tolerance may be a scalar value, which applies the same tolerance
3689 to all values, or list-like, which applies variable tolerance per
3690 element. List-like includes list, tuple, array, Series, and must be
3691 the same size as the index and its dtype must exactly match the
3692 index&#x27;s type.
3693
3694 Returns
3695 -------
3696 np.ndarray[np.intp]
3697 Integers from 0 to n - 1 indicating that the index at these
3698 positions matches the corresponding target values. Missing values
3699 in the target are marked by -1.
3700
3701 See Also
3702 --------
3703 Index.get_indexer_for : Returns an indexer even when non-unique.
3704 Index.get_non_unique : Returns indexer and masks for new index given
3705 the current index.
3706
3707 Notes
3708 -----
3709 Returns -1 for unmatched values, for further explanation see the
3710 example below.
3711
3712 Examples
3713 --------
3714 >>> index = pd.Index(["c", "a", "b"])

Callers 15

_unionMethod · 0.95
_get_nearest_indexerMethod · 0.95
reindexMethod · 0.95
asofMethod · 0.95
get_indexer_forMethod · 0.95
test_get_indexerMethod · 0.95
test_get_indexerMethod · 0.95

Calls 15

_should_compareMethod · 0.95
_should_partial_indexMethod · 0.95
get_locMethod · 0.95
equalsMethod · 0.95
astypeMethod · 0.95
_get_indexerMethod · 0.95