Skip to content

Added alignable boolean series and its example to .loc docs. #35506

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions pandas/core/indexing.py
Original file line number Diff line number Diff line change
Expand Up @@ -255,6 +255,8 @@ def loc(self) -> "_LocIndexer":

- A boolean array of the same length as the axis being sliced,
e.g. ``[True, False, True]``.
- An alignable boolean Series. The index of the key will be aligned before
masking.
- A ``callable`` function with one argument (the calling Series or
DataFrame) and that returns valid output for indexing (one of the above)

Expand All @@ -264,6 +266,8 @@ def loc(self) -> "_LocIndexer":
------
KeyError
If any items are not found.
IndexingError
If an indexed key is passed and its index is unalignable to the frame index.

See Also
--------
Expand Down Expand Up @@ -319,6 +323,13 @@ def loc(self) -> "_LocIndexer":
max_speed shield
sidewinder 7 8

Alignable boolean Series:

>>> df.loc[pd.Series([False, True, False],
... index=['viper', 'sidewinder', 'cobra'])]
max_speed shield
sidewinder 7 8

Conditional that returns a boolean Series

>>> df.loc[df['shield'] > 6]
Expand Down