Pandas로 CSV를 읽는 와중, ParserError가 발생하였다.
pd_data = pd.read_csv(train_loc, encoding='utf=8')
에러 메세지
Traceback (most recent call last):
File "D:/Project/steel/python/xjob_train.py", line 26, in <module>
pd_data = pd.read_csv(train_loc, encoding='utf=8')
File "C:\Users\user\anaconda3\lib\site-packages\pandas\io\parsers.py", line 676, in parser_f
return _read(filepath_or_buffer, kwds)
File "C:\Users\user\anaconda3\lib\site-packages\pandas\io\parsers.py", line 454, in _read
data = parser.read(nrows)
File "C:\Users\user\anaconda3\lib\site-packages\pandas\io\parsers.py", line 1133, in read
ret = self._engine.read(nrows)
File "C:\Users\user\anaconda3\lib\site-packages\pandas\io\parsers.py", line 2037, in read
data = self._reader.read(nrows)
File "pandas\_libs\parsers.pyx", line 860, in pandas._libs.parsers.TextReader.read
File "pandas\_libs\parsers.pyx", line 875, in pandas._libs.parsers.TextReader._read_low_memory
File "pandas\_libs\parsers.pyx", line 929, in pandas._libs.parsers.TextReader._read_rows
File "pandas\_libs\parsers.pyx", line 916, in pandas._libs.parsers.TextReader._tokenize_rows
File "pandas\_libs\parsers.pyx", line 2071, in pandas._libs.parsers.raise_parser_error
pandas.errors.ParserError: Error tokenizing data. C error: Expected 169 fields in line 11, saw 214
위 에러는 CSV에서 정상적이지 않는 데이터 즉 Bad 데이터의 문제로 발생을 하는데 이는 옵션 하나로 처리가 가능하다.
수정한 소스
pd_data = pd.read_csv(train_loc, encoding='utf=8', error_bad_lines=False)
반응형
'Stackoverflow > Python' 카테고리의 다른 글
The default value of regex will change from True to False in a future version. (0) | 2022.02.14 |
---|---|
[Python] module 'urllib' has no attribute 'request' (0) | 2022.01.11 |
UserWarning: The gensim.similarities.levenshtein submodule is disable (0) | 2021.05.18 |
[Python] you need to install visual studio for c++ (0) | 2021.01.09 |
CondaHTTPError: HTTP 000 CONNECTION FAILED (0) | 2021.01.04 |