-
-
Notifications
You must be signed in to change notification settings - Fork 19.4k
DOC: CoW and chained assignments: add solution #63310
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
base: main
Are you sure you want to change the base?
Conversation
rhshadrach
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good!
| need to convert the column name to its position using :meth:`Index.get_loc` or you need | ||
| to convert the row position to its index. Both variants as shown in the following snippet: | ||
|
|
||
| .. code-block:: ipython |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We only use code-block when demonstrating old behavior that is no longer the case. Can you instead use .. ipython:: python (see other sections of this file for examples).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure, will do!
This distinction just wasn't obvious at all - it just seemed random to me.
| need to convert the column name to its position using :meth:`Index.get_loc` or you need | ||
| to convert the row position to its index. Both variants as shown in the following snippet: | ||
|
|
||
| .. ipython:: python |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would maybe move this example to the "Chained Assignment" section below (and we can link from here to there, indicating that writing it as a single statement has to avoid chained assignment).
Because in the end, the question here is how to write df["foo"].iloc[0] = 100 without chained assignment. I think it is good to show that as an explicit example, since I think this is a quite common use case currently of chained assignment (as it is the only way to combine positional/label based without using the workarounds shown here).
doc/source/whatsnew/vX.X.X.rstfile if fixing a bug or adding a new feature.AGENTS.md.