python - pandas : pandas. io.common.CParserError 错误:标记数据时出错

标签 python python-3.x pandas

当我运行这个脚本时,它不起作用,我不知道为什么。你能帮我吗?

import pandas as pd
data1 = pd.read_csv(url)
print(data1)

错误:

Traceback (most recent call last):
  File "C:\Users\abc\Desktop\script.py", line 4, in <module>
    data1 = pd.read_csv(url)
  File "C:\Users\abc\AppData\Local\Programs\Python\Python36-32\lib\site-packages\pandas\io\parsers.py", line 646, in parser_f
    return _read(filepath_or_buffer, kwds)
  File "C:\Users\abc\AppData\Local\Programs\Python\Python36-32\lib\site-packages\pandas\io\parsers.py", line 401, in _read
    data = parser.read()
  File "C:\Users\abc\AppData\Local\Programs\Python\Python36-32\lib\site-packages\pandas\io\parsers.py", line 939, in read
    ret = self._engine.read(nrows)
  File "C:\Users\abc\AppData\Local\Programs\Python\Python36-32\lib\site-packages\pandas\io\parsers.py", line 1508, in read
   data = self._reader.read(nrows)
  File "pandas\parser.pyx", line 848, in pandas.parser.TextReader.read (pandas\parser.c:10415)
  File "pandas\parser.pyx", line 870, in pandas.parser.TextReader._read_low_memory (pandas\parser.c:10691)
  File "pandas\parser.pyx", line 924, in pandas.parser.TextReader._read_rows (pandas\parser.c:11437)
  File "pandas\parser.pyx", line 911, in pandas.parser.TextReader._tokenize_rows (pandas\parser.c:11308)
  File "pandas\parser.pyx", line 2024, in pandas.parser.raise_parser_error (pandas\parser.c:27037)
pandas.io.common.CParserError: Error tokenizing data. C error: Expected 45 fields in line 49, saw 46

谢谢!

最佳答案

在 pandas 句柄中,您应该传入 csv 的位置。

示例: pd.read_csv(存档位置) 喜欢: pd.read_csv(myfile.csv)

仅此而已!

关于python - pandas : pandas. io.common.CParserError 错误:标记数据时出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46404523/

相关文章:

python - 如果实例记录在类字典中,__del__ 不起作用

python - 删除 Pandas Dataframe 列范围内每列总和小于 10 的列

python - Pandas:检查列中是否存在值,该列存储为列表

python - 如果存在特定单词,则将行值替换为 NaN - Python

Python密码学包RSA——将私钥保存到DB

python - Timeit, NameError : global name is not defined. 但我没有使用全局变量

python win32com 导致程序崩溃

python - 在 celery 任务上禁用缓存

Python TypeError : a bytes-like object is required, 不是 'str'

python - 从python中的 Pandas 系列中删除元素