Skip to content

Commit 0f678a9

Browse files
DOC: Document and annotate Index.reindex (#40328). (#44037)
1 parent 2b05c91 commit 0f678a9

File tree

1 file changed

+43
-0
lines changed

1 file changed

+43
-0
lines changed

pandas/core/indexes/base.py

+43
Original file line numberDiff line numberDiff line change
@@ -3963,13 +3963,56 @@ def reindex(
39633963
Parameters
39643964
----------
39653965
target : an iterable
3966+
method : {None, 'pad'/'ffill', 'backfill'/'bfill', 'nearest'}, optional
3967+
* default: exact matches only.
3968+
* pad / ffill: find the PREVIOUS index value if no exact match.
3969+
* backfill / bfill: use NEXT index value if no exact match
3970+
* nearest: use the NEAREST index value if no exact match. Tied
3971+
distances are broken by preferring the larger index value.
3972+
level : int, optional
3973+
Level of multiindex.
3974+
limit : int, optional
3975+
Maximum number of consecutive labels in ``target`` to match for
3976+
inexact matches.
3977+
tolerance : int or float, optional
3978+
Maximum distance between original and new labels for inexact
3979+
matches. The values of the index at the matching locations must
3980+
satisfy the equation ``abs(index[indexer] - target) <= tolerance``.
3981+
3982+
Tolerance may be a scalar value, which applies the same tolerance
3983+
to all values, or list-like, which applies variable tolerance per
3984+
element. List-like includes list, tuple, array, Series, and must be
3985+
the same size as the index and its dtype must exactly match the
3986+
index's type.
39663987
39673988
Returns
39683989
-------
39693990
new_index : pd.Index
39703991
Resulting index.
39713992
indexer : np.ndarray[np.intp] or None
39723993
Indices of output values in original index.
3994+
3995+
Raises
3996+
------
3997+
TypeError
3998+
If ``method`` passed along with ``level``.
3999+
ValueError
4000+
If non-unique multi-index
4001+
ValueError
4002+
If non-unique index and ``method`` or ``limit`` passed.
4003+
4004+
See Also
4005+
--------
4006+
Series.reindex
4007+
DataFrame.reindex
4008+
4009+
Examples
4010+
--------
4011+
>>> idx = pd.Index(['car', 'bike', 'train', 'tractor'])
4012+
>>> idx
4013+
Index(['car', 'bike', 'train', 'tractor'], dtype='object')
4014+
>>> idx.reindex(['car', 'bike'])
4015+
(Index(['car', 'bike'], dtype='object'), array([0, 1]))
39734016
"""
39744017
# GH6552: preserve names when reindexing to non-named target
39754018
# (i.e. neither Index nor Series).

0 commit comments

Comments
 (0)