From 0f2282e3666cd84382575f31f023ad392b784c20 Mon Sep 17 00:00:00 2001 From: Jun Kudo Date: Fri, 2 Oct 2020 19:22:39 +0000 Subject: [PATCH 1/2] DOC: add example & prose of slicing with labels when index has duplicate labels #36251 --- doc/source/user_guide/indexing.rst | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/doc/source/user_guide/indexing.rst b/doc/source/user_guide/indexing.rst index b11baad1e3eb5..8e05b14e6a1bb 100644 --- a/doc/source/user_guide/indexing.rst +++ b/doc/source/user_guide/indexing.rst @@ -422,6 +422,17 @@ above example, ``s.loc[1:6]`` would raise ``KeyError``. For the rationale behind this behavior, see :ref:`Endpoints are inclusive `. +.. ipython:: python + + s = pd.Series(list('abcdef'), index=[0, 3, 2, 5, 4, 2]) + s.loc[3:5] + +Also, if the index has duplicate labels *and* either the start or the stop labels is dupulicate labels, +an error will be raised. For instance, in the above example, ``s.loc[2:5]`` would raise ``KeyError``. + +For more information about duplicate labels, see +:ref:`Duplicate Labels `. + .. _indexing.integer: Selection by position From 5559ad7b69883f114e4d16155be4db37abbefc42 Mon Sep 17 00:00:00 2001 From: Jun Kudo Date: Wed, 7 Oct 2020 15:19:11 +0000 Subject: [PATCH 2/2] DOC: proofread the sentence. --- doc/source/user_guide/indexing.rst | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/doc/source/user_guide/indexing.rst b/doc/source/user_guide/indexing.rst index 43c89aeddf783..44e2d8daa4de0 100644 --- a/doc/source/user_guide/indexing.rst +++ b/doc/source/user_guide/indexing.rst @@ -427,8 +427,8 @@ For the rationale behind this behavior, see s = pd.Series(list('abcdef'), index=[0, 3, 2, 5, 4, 2]) s.loc[3:5] -Also, if the index has duplicate labels *and* either the start or the stop labels is dupulicate labels, -an error will be raised. For instance, in the above example, ``s.loc[2:5]`` would raise ``KeyError``. +Also, if the index has duplicate labels *and* either the start or the stop label is dupulicated, +an error will be raised. For instance, in the above example, ``s.loc[2:5]`` would raise a ``KeyError``. For more information about duplicate labels, see :ref:`Duplicate Labels `.