Skip to content

DOC: add examples for setting using .loc #53251

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 2 commits into from
May 16, 2023
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
20 changes: 20 additions & 0 deletions pandas/core/indexing.py
Original file line number Diff line number Diff line change
Expand Up @@ -444,6 +444,26 @@ def loc(self) -> _LocIndexer:
viper 0 0
sidewinder 0 0

Add value matching location

>>> df.loc["viper", "shield"] += 5
>>> df
max_speed shield
cobra 30 10
viper 0 5
sidewinder 0 0

Setting using a ``Series`` or a ``DataFrame`` sets the values matching the
index labels, not the index positions.

>>> shuffled_df = df.loc[["viper", "cobra", "sidewinder"]]
>>> df.loc[:] += shuffled_df
>>> df
max_speed shield
cobra 60 20
viper 0 10
sidewinder 0 0

**Getting values on a DataFrame with an index that has integer labels**

Another example using integers for the index
Expand Down