Pandas Reading csv – Error

Question:

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?

Asked By: i2_

||

Answers:

Try adding the argument error_bad_lines=False to read_csv

Answered By: Ted Petrou

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)
Answered By: Ahmed Ali
Categories: questions Tags: ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.