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

Error in nsfg.py at line 98 for item() #83

Closed anmolgupta closed 2 years ago

anmolgupta commented 7 years ago

First of all, I would like to thank you for such a lovely tutorial. I found an error at line 98 in nsfg.py that item() function is not there. Do I need to use compulsary use Python3 as your git repo says? It may sounds silly but I am a newbee on this

gbremer commented 7 years ago

On behalf of the owner, thank you for the issue report. What is the exception and stacktrace of the error and how did you get there?

anmolgupta commented 7 years ago

This is the stack trace:

Traceback (most recent call last): File "/Users/anmol/ThinkStats2/code/nsfg.py", line 165, in <module> main() File "/Users/anmol/notebook/ThinkStats2/code/nsfg.py", line 158, in main assert(ValidatePregnum(resp, preg)) File "/Users/anmol/notebook/ThinkStats2/code/nsfg.py", line 98, in ValidatePregnum for index, pregnum in resp.pregnum.items(): File "/usr/local/lib/python2.7/site-packages/pandas/core/generic.py", line 3077, in __getattr__ return object.__getattribute__(self, name) AttributeError: 'Series' object has no attribute 'items'

I am on python 2.7.12 and pandas version is 0.20.3

I am running the files individually to understand how it works

gbremer commented 7 years ago

This looks like an issue that #79 described. I am suspecting that something changed in pandas, that the items() method has been removed, but have not looked at older versions yet to confirm that guess. An immediate fix for you is to change that items() method call to iteritems() and move on. You can wait for a proper fix -- I have been sticking my nose in here recently, and will get to it -- or you can make the fix and submit a pull request to AllenDowney for review.

anmolgupta commented 7 years ago

Thanks for your immediate reply. Changing to iteritems() works.

AllenDowney commented 7 years ago

This one it my fault. I was trying to clean up Python 2/3 incompatibilities and I introduced this error. I'll fix it right now.

Allen

On Wed, Aug 30, 2017 at 9:27 AM, Grant Bremer notifications@github.com wrote:

This looks like an issue that #79 https://github.com/AllenDowney/ThinkStats2/issues/79 described. I am suspecting that something changed in pandas, that the items() method has been removed, but have not looked at older versions yet to confirm that guess. An immediate fix for you is to change that items() method call to iteritems() and move on. You can wait for a proper fix -- I have been sticking my nose in here recently, and will get to it -- or you can make the fix and submit a pull request to AllenDowney for review.

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/AllenDowney/ThinkStats2/issues/83#issuecomment-325989650, or mute the thread https://github.com/notifications/unsubscribe-auth/ABy37YiQMeCs5UhLSI-7wikL9fLGrqThks5sdWMpgaJpZM4PHRzl .

AllenDowney commented 7 years ago

Done 19c22ed6f36adb27ebb2497db53ea460945b7cb5

On Wed, Aug 30, 2017 at 9:45 AM, Allen Downey allendowney@gmail.com wrote:

This one it my fault. I was trying to clean up Python 2/3 incompatibilities and I introduced this error. I'll fix it right now.

Allen

On Wed, Aug 30, 2017 at 9:27 AM, Grant Bremer notifications@github.com wrote:

This looks like an issue that #79 https://github.com/AllenDowney/ThinkStats2/issues/79 described. I am suspecting that something changed in pandas, that the items() method has been removed, but have not looked at older versions yet to confirm that guess. An immediate fix for you is to change that items() method call to iteritems() and move on. You can wait for a proper fix -- I have been sticking my nose in here recently, and will get to it -- or you can make the fix and submit a pull request to AllenDowney for review.

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/AllenDowney/ThinkStats2/issues/83#issuecomment-325989650, or mute the thread https://github.com/notifications/unsubscribe-auth/ABy37YiQMeCs5UhLSI-7wikL9fLGrqThks5sdWMpgaJpZM4PHRzl .

TanwarAbhishek commented 4 years ago

I am facing this issue while running nsfg.py file in anaconda prompt(anaconda3) i am having this file on desktop already please suggest a solution

SyntaxError: invalid syntax

(base) C:\Users\abhis\Desktop>nsfg File "C:\Users\abhis\Desktop\nsfg.py", line 7 <!DOCTYPE html> ^

AllenDowney commented 4 years ago

You should be able to run it on the command line like this:

python nsfg.py

But I suggest you don't. I recommend you use the Jupyter notebooks.

Allen

On Mon, May 18, 2020, at 11:15 AM, TanwarAbhishek wrote:

I am facing this issue while running nsfg.py file in anaconda prompt(anaconda3) i am having this file on desktop already please suggest a solution

SyntaxError: invalid syntax

(base) C:\Users\abhis\Desktop>nsfg File "C:\Users\abhis\Desktop\nsfg.py", line 7

^

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/AllenDowney/ThinkStats2/issues/83#issuecomment-630250402, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAOLP3PCXHJYOKYDJACWEP3RSFGHNANCNFSM4DY5DTSQ.