Skip to content

Commit 31db14c

Browse files
junjunjunkJun Kudo
and
Jun Kudo
authored
DOC: add example & prose of slicing with labels when index has duplicate labels (#36814)
* DOC: add example & prose of slicing with labels when index has duplicate labels #36251 * DOC: proofread the sentence. Co-authored-by: Jun Kudo <[email protected]>
1 parent 22de62c commit 31db14c

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 label is dupulicated,
431+
an error will be raised. For instance, in the above example, ``s.loc[2:5]`` would raise a ``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)