Skip to content

Commit d684b99

Browse files
committed
DOC: added basic example reindex func GH40328
1 parent 9a657cd commit d684b99

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

pandas/core/indexes/base.py

+21
Original file line numberDiff line numberDiff line change
@@ -3795,6 +3795,27 @@ def reindex(self, target, method=None, level=None, limit=None, tolerance=None):
37953795
Resulting index.
37963796
indexer : np.ndarray or None
37973797
Indices of output values in original index.
3798+
3799+
3800+
Examples
3801+
--------
3802+
>>> index = ['a', 'b', 'c', 'd']
3803+
>>> df = pd.DataFrame({"A": [1,2,3,4],
3804+
... "B": [5,6,7,8],
3805+
... "C": [9,10,11,12]},
3806+
... index=index)
3807+
>>> df
3808+
A B C
3809+
a 1 5 9
3810+
b 2 6 10
3811+
c 3 7 11
3812+
d 4 8 12
3813+
>>> target, indexer = df.index.reindex(target=['I', 'II', 'III', 'IV'])
3814+
>>> target, indexer
3815+
(Index(['I', 'II', 'III', 'IV'], dtype='object'), array([-1, -1, -1, -1]))
3816+
>>> target, indexer = df.index.reindex(target=['I', 'd', 'a', 'IV'])
3817+
>>> target, indexer
3818+
(Index(['I', 'd', 'III', 'IV'], dtype='object'), array([-1, 3, 0, -1]))
37983819
"""
37993820
# GH6552: preserve names when reindexing to non-named target
38003821
# (i.e. neither Index nor Series).

0 commit comments

Comments
 (0)