diff --git a/pandas/core/indexing.py b/pandas/core/indexing.py index 38bf6c34bf9c9..4a2803f638c73 100644 --- a/pandas/core/indexing.py +++ b/pandas/core/indexing.py @@ -400,6 +400,29 @@ def loc(self) -> _LocIndexer: max_speed sidewinder 7 + Multiple conditional using ``&`` that returns a boolean Series + + >>> df.loc[(df['max_speed'] > 1) & (df['shield'] < 8)] + max_speed shield + viper 4 5 + + Multiple conditional using ``|`` that returns a boolean Series + + >>> df.loc[(df['max_speed'] > 4) | (df['shield'] < 5)] + max_speed shield + cobra 1 2 + sidewinder 7 8 + + Please ensure that each condition is wrapped in parentheses ``()``. + See the :ref:`user guide` + for more details and explanations of Boolean indexing. + + .. note:: + If you find yourself using 3 or more conditionals in ``.loc[]``, + consider using :ref:`advanced indexing`. + + See below for using ``.loc[]`` on MultiIndex DataFrames. + Callable that returns a boolean Series >>> df.loc[lambda df: df['shield'] == 8]