i2_
i2_

Reputation: 735

Pandas Reading csv - Error

I have a problem with reading a CSV file with pandas (I know there are other topics but I could not solve the problem). My code is:

import pandas as pd
f = pd.read_csv('1803Ltem.csv',sep='\t', dtype=object,)

The error I get is:

    Traceback (most recent call last):
  File "/username/username/Documents/first.py", line 362, in <module>
    fuck = pd.read_csv('1803Ltem.csv',sep='\t', dtype=object,)
  File "/Users/username/anaconda/lib/python3.5/site-packages/pandas/io/parsers.py", line 562, in parser_f
    return _read(filepath_or_buffer, kwds)
  File "/Users/username/anaconda/lib/python3.5/site-packages/pandas/io/parsers.py", line 325, in _read
    return parser.read()
  File "/Users/username/anaconda/lib/python3.5/site-packages/pandas/io/parsers.py", line 815, in read
    ret = self._engine.read(nrows)
  File "/Users/username/anaconda/lib/python3.5/site-packages/pandas/io/parsers.py", line 1314, in read
    data = self._reader.read(nrows)
  File "pandas/parser.pyx", line 805, in pandas.parser.TextReader.read (pandas/parser.c:8748)
  File "pandas/parser.pyx", line 827, in pandas.parser.TextReader._read_low_memory (pandas/parser.c:9003)
  File "pandas/parser.pyx", line 881, in pandas.parser.TextReader._read_rows (pandas/parser.c:9731)
  File "pandas/parser.pyx", line 868, in pandas.parser.TextReader._tokenize_rows (pandas/parser.c:9602)
  File "pandas/parser.pyx", line 1865, in pandas.parser.raise_parser_error (pandas/parser.c:23325)
pandas.io.common.CParserError: Error tokenizing data. C error: Expected 4 fields in line 4587, saw 5

What am I doing wrong?

Upvotes: 0

Views: 1776

Answers (2)

Ahmed Ali
Ahmed Ali

Reputation: 51

The following worked for me by adding:

import pandas as pd
f = pd.read_csv('1803Ltem.csv',sep='\t', dtype=object,error_bad_lines=False)

Upvotes: 0

Ted Petrou
Ted Petrou

Reputation: 62037

Try adding the argument error_bad_lines=False to read_csv

Upvotes: 2

Related Questions