Skip to content

Commit f145027

Browse files
author
tp
committed
Added examples to pd.Index.get_loc
1 parent 77bfe21 commit f145027

File tree

1 file changed

+14
-1
lines changed

1 file changed

+14
-1
lines changed

pandas/core/indexes/base.py

+14-1
Original file line numberDiff line numberDiff line change
@@ -2450,7 +2450,20 @@ def _get_unique_index(self, dropna=False):
24502450
24512451
Returns
24522452
-------
2453-
loc : int if unique index, possibly slice or mask if not
2453+
loc : int if unique index, slice if monotonic index, else mask
2454+
2455+
Examples
2456+
---------
2457+
>>> unique_index = pd.Index(list('abc'))
2458+
>>> unique_index.get_loc('b')
2459+
1
2460+
>>> monotonic_index = pd.Index(list('abbc'))
2461+
>>> monotonic_index.get_loc('b')
2462+
slice(1, 3, None)
2463+
>>> non_monotonic_index = pd.Index(list('abcb'))
2464+
>>> non_monotonic_index.get_loc('b')
2465+
array([False, True, False, True], dtype=bool)
2466+
24542467
"""
24552468

24562469
@Appender(_index_shared_docs['get_loc'])

0 commit comments

Comments
 (0)