Issue
I am getting the following error when I try to upload a csv file after deleting a few rows in Numbers on Mac:
ParserError: Error tokenizing data. C error: Expected 1 fields in line 5, saw 2
To read the file I am using
df=pd.read_csv('path/file_name.csv')
Do you know the reason why I am getting that error message? Rows seem to be ok.
Thanks
Solution
Hard to say without a subset of data, however you could give a the try either to
- set the
sep
parameter if your file is not separated by comma,
(which is the default value) - switch the engine to Python by setting the
engine="python"
parameter.
df = pd.read_csv('path/file_name.csv', sep=';', engine='python')
But maybe it's a problem in the file itself and one or more rows in the file have more fields than the others. In this case you can get rid of them instead of returning an error by setting on_bad_lines
flag.
df = pd.read_csv('path/file_name.csv', on_bad_lines='skip')
skip bad lines without raising or warning when they are encountered.
Answered By - Romain
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.