-
Notifications
You must be signed in to change notification settings - Fork 329
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
Feature Request: Add example using the comparison operator to assign a new boolean column #1
Comments
Hey @skilfullycurled thanks for the response. I really appreciate any comments that can make this tutorial better. Assigning a new column directly from the same dataframe should not produce any warning. Let's take a concrete example.
If we create a new boolean column directly from column
I noticed that your example Can you provide all of the code that produces the warning? And yes, |
Ah. I think I see the problem now. After a day of still getting warnings under various circumstances, I'm finally getting to wrap my mind around it. It's the issue of assigning to a view vs. a copy. Exactly as you wrote:
Given my experience of finally coming to understand this difference, I'll reframe my suggestion: Depending on who your audience is, you might think about adding an example that throws this error at the beginning of the post before getting into the details. I think sometimes it's helpful to begin with a practical example before going into the details. Right now the order is sort of:
A different logic that might help contextualize chained indexing:
Again, this is a great tutorial. Understanding the selection of data in such a deep but accessible way really clarified the issue. As you noted at the end, the warning is really poorly written. |
Oh. What I quoted above brings up one more thing. At the top you wrote:
Then later in the example you wrote:
When I was researching the issue, I read that in some circumstances the issue is that the change will not propagate backwards to the original, and it other circumstances it will not propagate forwards to the intermediate. See firelynx's and Raphanns' response. Raphanns example is not about selecting subsets so perhaps it does not apply. |
Hello,
First, thank you so much for these great tutorials. There are a number of warnings regarding the usage of "just the indexing operator" for quite a while and the explanation of .loc and .iloc were tremendously helpful.
I'm writing to recommend that you add an example of assigning a new column from a boolean selection that returns a boolean series in the article on assignment. Take for example, the following:
Using just the assignment operator...
...works but yields the warning:
The closest example I've found in your article is this one:
However, at least in Pandas 0.19.2, this will still yield the same error. After searching around a bit I found this stack overflow discussion which states that after Pandas 0.16.0, the best way to do this is to use the assign function in the following manner:
Which seems to work well for me.
Alternatively, I suppose you can simply add which version the tutorial was written under.
Thanks again for this wonderful guide!
The text was updated successfully, but these errors were encountered: