Python 脚本可以工作,但抛出错误 - pandas.errors 标记数据

我是Python新手。我正在尝试从请求读取 json 响应并使用 pandas 进行过滤以保存在 csv 文件中。该脚本可以工作并为我提供所有数据,但执行后会抛出此错误 -


我无法弄清楚为什么它会抛出此错误?我怎样才能通过这个错误?


错误 -


 script.py line 42, in <module>

 df = pd.read_csv("Data_script4.csv")

 File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-    

 packages/pandas/io/parsers.py", line 686, in read_csv

 return _read(filepath_or_buffer, kwds)

 File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-   

 packages/pandas/io/parsers.py", line 458, in _read

 data = parser.read(nrows)

 File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-   

 packages/pandas/io/parsers.py", line 1196, in read

 ret = self._engine.read(nrows)

 File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-  

 packages/pandas/io/parsers.py", line 2155, in read

 data = self._reader.read(nrows)

 File "pandas/_libs/parsers.pyx", line 847, in pandas._libs.parsers.TextReader.read

 File "pandas/_libs/parsers.pyx", line 862, in   

 pandas._libs.parsers.TextReader._read_low_memory

 File "pandas/_libs/parsers.pyx", line 918, in pandas._libs.parsers.TextReader._read_rows

 File "pandas/_libs/parsers.pyx", line 905, in   

 pandas._libs.parsers.TextReader._tokenize_rows

 File "pandas/_libs/parsers.pyx", line 2042, in pandas._libs.parsers.raise_parser_error

 pandas.errors.ParserError: Error tokenizing data. C error: Expected 9 fields in line 53,    

 saw 10


喵喵时光机
浏览 107回答 1
1回答

潇湘沐

这是要点:您需要替换:df = pd.read_csv("Data_script4.csv")有了这个:df = pd.read_csv('Data_script4.csv', error_bad_lines=False)
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

Python