Skip to content

Commit 6d34657

Browse files
topper-123jorisvandenbossche
authored andcommitted
DOC: Improve code example for Index.get_indexer (pandas-dev#21511)
1 parent 6131a59 commit 6d34657

File tree

1 file changed

+10
-5
lines changed

1 file changed

+10
-5
lines changed

pandas/core/indexes/base.py

+10-5
Original file line numberDiff line numberDiff line change
@@ -3148,17 +3148,22 @@ def droplevel(self, level=0):
31483148
31493149
.. versionadded:: 0.21.0 (list-like tolerance)
31503150
3151-
Examples
3152-
--------
3153-
>>> indexer = index.get_indexer(new_index)
3154-
>>> new_values = cur_values.take(indexer)
3155-
31563151
Returns
31573152
-------
31583153
indexer : ndarray of int
31593154
Integers from 0 to n - 1 indicating that the index at these
31603155
positions matches the corresponding target values. Missing values
31613156
in the target are marked by -1.
3157+
3158+
Examples
3159+
--------
3160+
>>> index = pd.Index(['c', 'a', 'b'])
3161+
>>> index.get_indexer(['a', 'b', 'x'])
3162+
array([ 1, 2, -1])
3163+
3164+
Notice that the return value is an array of locations in ``index``
3165+
and ``x`` is marked by -1, as it is not in ``index``.
3166+
31623167
"""
31633168

31643169
@Appender(_index_shared_docs['get_indexer'] % _index_doc_kwargs)

0 commit comments

Comments
 (0)