我正在尝试使用 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/