【问题标题】:Pandas read data from a secure FTP server in Python 3Pandas 从 Python 3 中的安全 FTP 服务器读取数据
【发布时间】:2018-06-27 11:55:18
【问题描述】:

我正在寻找一种简洁的解决方案,从 Python 3 中的安全 FTP 服务器读取数据(使用 read_csv 或 read_sas)到 Pandas Dataframe。我能找到的所有示例都是很多行,其中一些是针对 Python 2 的。是吗?是否有一种巧妙的方法可以将您的用户名+密码连同 ftp url 和文件夹一起插入到 Pandas read_csv-like 方法中?

【问题讨论】:

  • 值得注意的是,出于安全原因,我想将数据从 ftp 服务器文件直接读取到我的 Python 内存中

标签: python pandas csv ftp


【解决方案1】:

pandas.read_csv() 接受类似文件的对象。 Paramiko 是一个处理 SFTP 并可以提供类文件对象的库。一旦你set up the connection,它很简单:

with sftp.open("file.csv") as f:
    pd.read_csv(f)

【讨论】:

  • 这里假设是UTF-8编码,你们有处理其他编码的方案吗?
猜你喜欢
  • 1970-01-01
  • 2021-11-11
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2021-08-10
  • 2011-01-11
  • 2017-09-05
  • 2017-11-13
相关资源
最近更新 更多