Skip to content

Commit 0f2282e

Browse files
committed
DOC: add example & prose of slicing with labels when index has duplicate labels pandas-dev#36251
1 parent 6fc17fa commit 0f2282e

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

doc/source/user_guide/indexing.rst

+11
Original file line numberDiff line numberDiff line change
@@ -422,6 +422,17 @@ above example, ``s.loc[1:6]`` would raise ``KeyError``.
422422
For the rationale behind this behavior, see
423423
:ref:`Endpoints are inclusive <advanced.endpoints_are_inclusive>`.
424424

425+
.. ipython:: python
426+
427+
s = pd.Series(list('abcdef'), index=[0, 3, 2, 5, 4, 2])
428+
s.loc[3:5]
429+
430+
Also, if the index has duplicate labels *and* either the start or the stop labels is dupulicate labels,
431+
an error will be raised. For instance, in the above example, ``s.loc[2:5]`` would raise ``KeyError``.
432+
433+
For more information about duplicate labels, see
434+
:ref:`Duplicate Labels <duplicates>`.
435+
425436
.. _indexing.integer:
426437

427438
Selection by position

0 commit comments

Comments
 (0)