pandas.errors.ParserError: Error tokenizing data. C error: EOF inside string starting at line x

Created on 31 Jul 2018  路  3Comments  路  Source: pandas-dev/pandas

Data

Col1|Col2|Col3|Col4
Str1|1|p|num1
Str2|2|q|num2
Str3|3|"|num3
Str4|4|s|num4

Error

>>> import pandas as pd
>>> df = pd.read_csv('./sample.txt', sep='|')
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File ".env\lib\site-packages\pandas\io\parsers.py", line 678, in parser_f
    return _read(filepath_or_buffer, kwds)
  File ".env\lib\site-packages\pandas\io\parsers.py", line 446, in _read
    data = parser.read(nrows)
  File ".env\lib\site-packages\pandas\io\parsers.py", line 1036, in read
    ret = self._engine.read(nrows)
  File ".env\lib\site-packages\pandas\io\parsers.py", line 1848, in read
    data = self._reader.read(nrows)
  File "pandas\_libs\parsers.pyx", line 876, in pandas._libs.parsers.TextReader.read
  File "pandas\_libs\parsers.pyx", line 891, in pandas._libs.parsers.TextReader._read_low_memory
  File "pandas\_libs\parsers.pyx", line 945, in pandas._libs.parsers.TextReader._read_rows
  File "pandas\_libs\parsers.pyx", line 932, in pandas._libs.parsers.TextReader._tokenize_rows
  File "pandas\_libs\parsers.pyx", line 2112, in pandas._libs.parsers.raise_parser_error
pandas.errors.ParserError: Error tokenizing data. C error: EOF inside string starting at line 3
>>>

Problem description

The current error handling of error while parsing double quote (") in 'C' engine is vague. If the data is sensitive there is very less chance that you will get to have a look at the actual data. So, if the error is more specific it would be awesome. In my company we get less data for development which is masked of`course, but in production it is unclear why and where errors occurred.

If not as an error, display a warning saying that a " is present in between a line.

Expected Output

There is a weird character (") leading to EOF. " is taken as end of string.

Output of pd.show_versions()

[paste the output of pd.show_versions() here below this line]

INSTALLED VERSIONS

commit: None
python: 3.7.0.final.0
python-bits: 32
OS: Windows
OS-release: 10
machine: AMD64
processor: Intel64 Family 6 Model 158 Stepping 10, GenuineIntel
byteorder: little
LC_ALL: None
LANG: None
LOCALE: None.None

pandas: 0.23.3
pytest: None
pip: 18.0
setuptools: 40.0.0
Cython: None
numpy: 1.15.0
scipy: None
pyarrow: None
xarray: None
IPython: None
sphinx: None
patsy: None
dateutil: 2.7.3
pytz: 2018.5
blosc: None
bottleneck: None
tables: None
numexpr: None
feather: None
matplotlib: None
openpyxl: None
xlrd: None
xlwt: None
xlsxwriter: None
lxml: None
bs4: None
html5lib: None
sqlalchemy: None
pymysql: None
psycopg2: None
jinja2: None
s3fs: None
fastparquet: None
pandas_gbq: None
pandas_datareader: None

IO CSV Usage Question

Most helpful comment

Closing as an error is certainly the right thing to do here instead of issuing a warning.

If you don't want quoting you can disable it as follows:

pd.read_csv(SOME_OBJECT, quotechar=None, quoting=3)

All 3 comments

Closing as an error is certainly the right thing to do here instead of issuing a warning.

If you don't want quoting you can disable it as follows:

pd.read_csv(SOME_OBJECT, quotechar=None, quoting=3)

I didn't know it was because of a quote until I looked into the data.

I have a same error.
in my case, file is not yet uploaded or downloaded.
after complete uploading, there is no error.
please check download or upload is complete or not
thanks.

Was this page helpful?
0 / 5 - 0 ratings