diff --git a/pandas/core/indexing.py b/pandas/core/indexing.py index 2f0b6ab0662dd..e3c94fa3941c0 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 (same behavior as ``df.reindex``) + + >>> 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]