From a1004d5e947a2501e40181af0e8f48f7fd091d59 Mon Sep 17 00:00:00 2001 From: Shao Yang Hong Date: Fri, 27 Nov 2020 20:47:05 +0800 Subject: [PATCH 1/2] DOC: Add behavior for Index argument in DataFrame.loc --- pandas/core/indexing.py | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/pandas/core/indexing.py b/pandas/core/indexing.py index 2f0b6ab0662dd..f72bd8486b6a2 100644 --- a/pandas/core/indexing.py +++ b/pandas/core/indexing.py @@ -259,10 +259,11 @@ def loc(self) -> "_LocIndexer": e.g. ``[True, False, True]``. - An alignable boolean Series. The index of the key will be aligned before masking. + - An alignable Index. The Index of the returned selection will be the input. - A ``callable`` function with one argument (the calling Series or DataFrame) and that returns valid output for indexing (one of the above) - See more at :ref:`Selection by Label ` + See more at :ref:`Selection by Label `. Raises ------ @@ -332,6 +333,14 @@ def loc(self) -> "_LocIndexer": max_speed shield sidewinder 7 8 + Index: + + >>> df.loc[pd.Index(["cobra", "viper"], name="foo")] + max_speed shield + foo + cobra 1 2 + viper 4 5 + Conditional that returns a boolean Series >>> df.loc[df['shield'] > 6] From 09386579653265f1c1df24a7b7d2a4c81ef69ac6 Mon Sep 17 00:00:00 2001 From: Shao Yang Hong Date: Sun, 29 Nov 2020 17:06:43 +0800 Subject: [PATCH 2/2] indicate behavior --- pandas/core/indexing.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pandas/core/indexing.py b/pandas/core/indexing.py index f72bd8486b6a2..e3c94fa3941c0 100644 --- a/pandas/core/indexing.py +++ b/pandas/core/indexing.py @@ -333,7 +333,7 @@ def loc(self) -> "_LocIndexer": max_speed shield sidewinder 7 8 - Index: + Index (same behavior as ``df.reindex``) >>> df.loc[pd.Index(["cobra", "viper"], name="foo")] max_speed shield