question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Iterate through Pandas throughs error only in Spyder

See original GitHub issue

Description

What steps will reproduce the problem?

import pandas as pd

import numpy as np

df = pd.DataFrame(np.random.randn(4,3),columns = [‘col1’,‘col2’,‘col3’])

for row in df.itertuples(): File “<ipython-input-29-80c0315d0c1a>”, line 1 for row in df.itertuples(): ^ SyntaxError: unexpected EOF while parsing

whenever I try to iterate through a pandas dataframe I get an "unexpected EOF while parsing. This does not occur with other Python IDEs.

Versions

  • Spyder version: 3.3.6
  • Python version: 3.7.4
  • Qt version: 5.9.6
  • PyQt5 version: 5.9.2
  • Operating System: Windows 10

Dependencies

pyflakes >=0.6.0  :  2.1.1 (OK)
pycodestyle >=2.3 :  2.5.0 (OK)
pygments >=2.0    :  2.4.2 (OK)
sphinx >=0.6.6    :  2.2.0 (OK)
rope >=0.9.4      :  0.14.0 (OK)
jedi >=0.9.0      :  0.15.1 (OK)
nbconvert >=4.0   :  5.6.0 (OK)
pandas >=0.13.1   :  0.25.1 (OK)
numpy >=1.7       :  1.16.5 (OK)
sympy >=0.7.3     :  1.4 (OK)
cython >=0.21     :  0.29.13 (OK)
qtconsole >=4.2.0 :  4.5.5 (OK)
IPython >=4.0     :  7.8.0 (OK)
matplotlib >=2.0.0:  3.1.1 (OK)
pylint >=0.25     :  2.4.2 (OK)

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:5 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
juanis2112commented, May 19, 2020

Hi @rjudgeGit please take a look at this issue #12469, maybe this can help.

1reaction
jitseniesencommented, May 16, 2020

@rjudgeGit Your code is incomplete, there should be something after the for statement. How do you run the code? You have to make sure you run the loop in its entirety.

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to iterate over rows in a DataFrame in Pandas
Answer: DON'T * ! Iteration in Pandas is an anti-pattern and is something you should only do when you have exhausted every other...
Read more >
How to iterate over DataFrame rows (and should you?)
How to iterate over a pandas DataFrame is a common question, but understanding how to do it and when to avoid it are...
Read more >
How to iterate over rows in Pandas: Most efficient options
This error occurs because each item in our iterrows() generator is a tuple-type object with two values, the row index and the row...
Read more >
KeyError Pandas – How To Fix - Data Independent
Pandas KeyError - This annoying error means that Pandas can not find your column name in your dataframe. Here's how to fix this...
Read more >
Using Pandas to Read Large Excel Files in Python
What happens? You should see a “File Not Loaded Completely” error since Excel can only handle one million rows at a time. We...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found