AllenDowney / ThinkStats2

Text and supporting code for Think Stats, 2nd Edition
http://allendowney.github.io/ThinkStats2/
GNU General Public License v3.0
4.03k stars 11.31k forks source link

fixes SettingWithCopyWarning in `nsfg.CleanFemPreg` #33

Closed benjaminEwhite closed 8 years ago

benjaminEwhite commented 8 years ago

When running the first cell in 1.9 exercises in ipython notebook, the nsfg.ReadFemPreg fails when calling CleanFemPreg with a SettingWithCopyWarning warning. In ipython notebook, this warning is displayed in a prominent red box, and is the first cell a reader runs.

Pandas docs advise against chained indexing for value assignment here.

This patch uses df.loc to get rid of the warning and updates book text accordingly. Even though there may be a desire to hold of on introducing .loc() until later (although I don't think it's harder or easier to understand than chained indexing), it seems to me it's worth it to help beginner users out by making their first experience running code from this book smoother.

AllenDowney commented 8 years ago

I just pushed e87b2a391324cc28a3730d374ac2894094db18f6 to fix this. Thanks!

benjaminEwhite commented 8 years ago

Glad to be of help @AllenDowney . Thanks for making this text publicly available. As I work through the materials, I'll post issues if I come across anything else.

AllenDowney commented 8 years ago

Thanks!

On Tue, Dec 1, 2015 at 2:46 PM, Benjamin E White notifications@github.com wrote:

Glad to be of help @AllenDowney https://github.com/AllenDowney . Thanks for making this text publicly available. As I work through the materials, I'll post issues if I come across anything else.

— Reply to this email directly or view it on GitHub https://github.com/AllenDowney/ThinkStats2/pull/33#issuecomment-161075320 .