Traceback (most recent call last): File "xian.py", line 6, in <module> data = pd.read_csv('/home/w123/Documents/data-analysis/40-0-data/ratio/40-10-ratio.txt', sep=',', header=None) File "/home/w123/anaconda3/envs/face/lib/python3.7/site-packages/pandas/util/_decorators.py", line 311, in wrapper return func(*args, **kwargs) File "/home/w123/anaconda3/envs/face/lib/python3.7/site-packages/pandas/io/parsers/readers.py", line 586, in read_csv return _read(filepath_or_buffer, kwds) File "/home/w123/anaconda3/envs/face/lib/python3.7/site-packages/pandas/io/parsers/readers.py", line 488, in _read return parser.read(nrows) File "/home/w123/anaconda3/envs/face/lib/python3.7/site-packages/pandas/io/parsers/readers.py", line 1047, in read index, columns, col_dict = self._engine.read(nrows) File "/home/w123/anaconda3/envs/face/lib/python3.7/site-packages/pandas/io/parsers/c_parser_wrapper.py", line 224, in read chunks = self._reader.read_low_memory(nrows) File "pandas/_libs/parsers.pyx", line 801, in pandas._libs.parsers.TextReader.read_low_memory File "pandas/_libs/parsers.pyx", line 857, in pandas._libs.parsers.TextReader._read_rows File "pandas/_libs/parsers.pyx", line 843, in pandas._libs.parsers.TextReader._tokenize_rows File "pandas/_libs/parsers.pyx", line 1925, in pandas._libs.parsers.raise_parser_error pandas.errors.ParserError: Error tokenizing data. C error: Expected 1 fields in line 2, saw 3
时间: 2023-10-01 16:11:45 浏览: 185
浅谈Python traceback的优雅处理
这个错误提示是由于 pandas 在读取 csv 文件时,无法正确地分隔数据。具体来说,它在读取第二行时期望只有一个字段,但实际上有三个字段。这通常是因为数据中包含了一些不规则的内容,例如特殊字符或文本中的逗号。建议你检查一下数据文件,确保每行的字段数都是一致的,并且没有不必要的空格或特殊字符。另外,你可以尝试使用不同的分隔符或引号字符来读取数据,以便正确地解析文件。
阅读全文