1

I cannot use read_csv method of pandas properly on kaggle. Error that I get is:

ParseError: Error tokenizing data. C error: Buffer overflow caught - possible malformed input file.

I found some suggestions about this (read_excel, read by column). However, they do not help me to solve this error.

10
  • Searching on this error message gives many good options such as a way to find exactly which line in the csv is bad, switching to the python engine, or defining a different line termination character (\n instead of \r\n). see stackoverflow.com/questions/33998740/… Commented Nov 10, 2020 at 5:22
  • I am using donald_trump CSV that in the kaggle.com/manchunhui/us-election-2020-tweets notebook. Verified answer of topic that you've send me is not good solution and it does not have enough description to make sense. Commented Nov 10, 2020 at 5:32
  • I found good solutation to fix this problem. Adding engine='python' to read_csv method as a parameter. pd.read_csv('csv_path', engine='python'). Ok - how does this solve a problem? Commented Nov 10, 2020 at 5:37
  • I don't know in this case, but CSV is generally loosely defined - some encoders may miss certain escapes that cause other parsers problems. Normally a CSV has \r\n line endings but if a lone \r is floating around in there, or there are other anomolies, some parsers will choke. Pandas normally uses a C parser that is not too forgiving. But it can also use a python one that will handle more cases. I can't say for sure what is messed up in this case. Commented Nov 10, 2020 at 5:43
  • Hmm, thanks. I understood the case. I did not know what pandas uses C engine to read csv. Otherwise, Using python engine enables us to scan and read csv(maybe excel) more flexible. Commented Nov 10, 2020 at 5:50

1 Answer 1

1

I solved the same problem just by adding engine='python':

df = pd.read_csv(fname, sep='\t',
                 engine='python',
                 header=None)
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.