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

Cannot Run Code #37

Closed loffelmacher closed 8 years ago

loffelmacher commented 8 years ago

I suppose that it's something I'm doing wrong, but anytime I try to run the code from my Mac OSX terminal I'm getting the following error:

./nsfg2.py: line 16: syntax error near unexpected token (' ./nsfg2.py: line 16:def MakeFrames():'

This happens right from the start, when I try to run ./nsfg2.py. I did install Anaconda and try to run my code through there, no dice. Could not figure out how to actually run a .py file from Anaconda.

So then I did some pip installs for the packages called-out in the book, I installed pandas, numpy, scipy, statsmodela, and matplotlib. Still getting this error message.

AllenDowney commented 8 years ago

nsfg2.py is not executable. Try

python nsfg.py

You might want to start with Think Python.

On Mon, Feb 8, 2016 at 6:03 PM, loffelmacher notifications@github.com wrote:

I suppose that it's something I'm doing wrong, but anytime I try to run the code from my Mac OSX terminal I'm getting the following error:

./nsfg2.py: line 16: syntax error near unexpected token (' ./nsfg2.py: line 16:def MakeFrames():'

This happens right from the start, when I try to run ./nsfg2.py. I did install Anaconda and try to run my code through there, no dice. Could not figure out how to actually run a .py file from Anaconda.

So then I did some pip installs for the packages called-out in the book, I installed pandas, numpy, scipy, statsmodela, and matplotlib. Still getting this error message.

— Reply to this email directly or view it on GitHub https://github.com/AllenDowney/ThinkStats2/issues/37.

loffelmacher commented 8 years ago

That was such a beginner mistake, I apologize! However I tried as suggested now I bump into the warning below. Also I am on Python 2.7.9.

nsfg2.py:57: SettingWithCopyWarning: 
A value is trying to be set on a copy of a slice from a DataFrame

See the caveats in the documentation: http://pandas.pydata.org/pandas-docs/stable/indexing.html#indexing-view-versus-copy
  df.birthwgt_lb1[df.birthwgt_lb1 > 20] = np.nan
AllenDowney commented 8 years ago

You can ignore that warning, but I will make a note to rewrite this to avoid the warning or suppress it.

On Tue, Feb 9, 2016 at 10:28 AM, loffelmacher notifications@github.com wrote:

That was such a beginner mistake, I apologize! However I tried as suggested now I bump into the warning below. Also I am on Python 2.7.9.

nsfg2.py:57: SettingWithCopyWarning: A value is trying to be set on a copy of a slice from a DataFrame

See the caveats in the documentation: http://pandas.pydata.org/pandas-docs/stable/indexing.html#indexing-view-versus-copy df.birthwgt_lb1[df.birthwgt_lb1 > 20] = np.nan

— Reply to this email directly or view it on GitHub https://github.com/AllenDowney/ThinkStats2/issues/37#issuecomment-181914130 .

loffelmacher commented 8 years ago

thanks for your help and this wonderful book!

yongduek commented 6 years ago

I had the same warning message and fixed it.

The warning will disappear by replacing the line df.birthwgt_lb1[df.birthwgt_lb1 > 20] = np.nan by df.loc[df.birthwgt_lb1 > 20, 'birthwgt_lb1'] = np.nan

cf.: How to deal with SettingWithCopyWarning in Pandas?

AllenDowney commented 6 years ago

This is now resolved with 2cfbdb0816be027dab9495ac152faecab7f1dc3e

(thanks to your PR)

On Tue, Apr 10, 2018 at 12:29 AM, yongduek notifications@github.com wrote:

The warning will disappear by replacing the line df.birthwgt_lb1[df.birthwgt_lb1 > 20] = np.nan by df.loc[df.birthwgt_lb1 > 20, 'birthwgt_lb1'] = np.nan

cf.: How to deal with SettingWithCopyWarning in Pandas? https://stackoverflow.com/questions/20625582/how-to-deal-with-settingwithcopywarning-in-pandas

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/AllenDowney/ThinkStats2/issues/37#issuecomment-379970292, or mute the thread https://github.com/notifications/unsubscribe-auth/ABy37QEn4fYa7H96iGfsF-noeWsb0r60ks5tnDU8gaJpZM4HV-em .