Update nsfg.py to fix FutureWarning#217
Conversation
Fix warning:
ThinkStats2/code/nsfg.py:66: FutureWarning: A value is trying to be set on a copy of a DataFrame or Series through chained assignment using an inplace method.
The behavior will change in pandas 3.0. This inplace method will never work because the intermediate object on which we are setting values always behaves as a copy.
For example, when doing 'df[col].method(value, inplace=True)', try using 'df.method({col: value}, inplace=True)' or df[col] = df[col].method(value) instead, to perform the operation inplace on the original object.
|
Thanks for this PR! It looks like this combines multiple calls to |
|
No it does not generate the warning. In fact, the warning gives the hint that this will work, and the way it was done before won't work in Pandas 3.0. Please read the full warning. |
|
Sorry, I was thinking of a different issue, the deprecation of |
|
Looks like there's a failing test that's unrelated to this PR, so let's get this merged and then I'll deal with the other issue. |
|
Also, I wanted to say, thank you for all your excellent free books and code! I'm going through the code notebooks of your book. I'll keep making pull requests whenever I find more such minor updates needed to make the code compatible with the latest versions of the used libraries. |
|
I appreciate that, but the 3rd edition is almost done. The online version is substantially complete at https://allendowney.github.io/ThinkStats/, and the print edition is going into production now. So if it is not too late, you might want to switch! |
|
Oh that's lovely! Thank you for pointing me to this! I just started, so perfect time for me to switch to your latest work! |
Fix warning: