python - Pandas CParseError,通过 FTP 下载的文件

标签 python pandas ftp ftplib

我正在尝试使用 read_csv 在 Pandas 中读取 csv 文件(通过 FTP 下载)

df = pandas.read_csv("file.csv")

但我收到错误:

CParserError: Error tokenizing data. C error: EOF inside string starting at line 652

通过FTP下载文件的代码:

f = open(file_name, 'wb')
ftp.retrbinary("RETR " + file_name, f.write)

但是当我在浏览器上下载相同的文件并解析它时,效果很好。请提出任何解决方案。

最佳答案

试试这个:

df = pandas.read_csv('ftp://...')  # puth there the real FTP URL

来自docs :

filepath_or_buffer : str, pathlib.

Path, py._path.local.LocalPath or any object with a read() method (such as a file handle or StringIO)

The string could be a URL. Valid URL schemes include http, ftp, s3, and file.

For file URLs, a host is expected. For instance, a local file could be file ://localhost/path/to/table.csv

关于python - Pandas CParseError,通过 FTP 下载的文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43823056/

相关文章:

具有多种功能的Python sklearn决策树分类器?

python - 折叠 Pandas 行以消除 NaN 条目

python - 如何计算列表值在不同数据框的列中的出现次数?

ftp - Azure网站FTP访问/530用户无法登录

python - withColumn 中的用户定义函数只调用一次而不是每个 DF 行

python - PyImport_Import 失败 - 返回 NULL

c# - 使用C#上传文件到FTP

python - 在我只有 ftp 访问权限的服务器上安装 pip 包?

python - 如何创建表并选择数据库中的任何列?

python - 如何访问滚动运算符中的多列?