-
-
Notifications
You must be signed in to change notification settings - Fork 18.8k
Description
-
I have checked that this issue has not already been reported.
-
I have confirmed this bug exists on the latest version of pandas.
-
(optional) I have confirmed this bug exists on the master branch of pandas.
(this was also posted to Stack Overflow, where I was told this seems like a bug https://stackoverflow.com/questions/66541816/pandas-read-csv-not-erroring-on-a-bad-line-with-extra-columns)
Code Sample, a copy-pastable example
I have the below simple csv
ownername,streetno,streetname
me,320,main st,just,absolute,garbage
you,40,mint ave
The command I'm using to read the file is
import csv
import pandas
file = 'path_to_csv'
data = pandas.read_csv(file,',',header=0, quotechar=None, quoting = csv.QUOTE_NONE, index_col=False)
As long as the extra values (just,absolute,garbage) occur on the first row of data, it will parse the file without errors, giving me the below DataFrame
ownername streetno streetname
0 me 320 main st
1 you 40 mint ave
Problem description
This is not erroring on the bad line with extra columns as long as the bad line is the first line of data. Explicitly setting error_bad_lines=True
has no effect.
Expected Output
Error tokenizing data. C error: Expected 3 fields in line 2, saw 6
, e.g. the same as what happens when the extra columns are only on the 2nd line of data.
Output of pd.show_versions()
INSTALLED VERSIONS
commit : f2c8480
python : 3.7.2.final.0
python-bits : 32
OS : Windows
OS-release : 10
Version : 10.0.19041
machine : AMD64
processor : Intel64 Family 6 Model 158 Stepping 10, GenuineIntel
byteorder : little
LC_ALL : None
LANG : en_US.UTF-8
LOCALE : None.None
pandas : 1.2.3
numpy : 1.20.1
pytz : 2021.1
dateutil : 2.8.1
pip : 21.0.1
setuptools : 54.1.1
Cython : None
pytest : None
hypothesis : None
sphinx : None
blosc : None
feather : None
xlsxwriter : None
lxml.etree : None
html5lib : None
pymysql : None
psycopg2 : None
jinja2 : None
IPython : None
pandas_datareader: None
bs4 : None
bottleneck : None
fsspec : None
fastparquet : None
gcsfs : None
matplotlib : None
numexpr : None
odfpy : None
openpyxl : 3.0.6
pandas_gbq : None
pyarrow : None
pyxlsb : None
s3fs : None
scipy : None
sqlalchemy : 1.3.23
tables : None
tabulate : None
xarray : None
xlrd : 2.0.1
xlwt : None
numba : None