Reading files from FTP server to DataFrame in Python(在 Python 中从 FTP 服务器读取文件到 DataFrame)
本文介绍了在 Python 中从 FTP 服务器读取文件到 DataFrame的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想将文件从 FTP 服务器加载到 Pandas 数据帧中,而无需先将其下载到磁盘.我写了一个脚本来执行这个命令,但下载到磁盘.这可能在 ftplib 库中吗?你觉得这个问题有什么解决办法吗?
I would like to load a file from an FTP server into Pandas dataframe without downloading it to disk first. I have written a script that executes this command but with downloading to disk. Is this possible in the ftplib library? Do you see any solution to this problem?
from ftplib import FTP
import os
import pandas as pd
ftps = FTP('gssc.esa.int')
ftps.login()
ftps.cwd('/gnss/data/daily/2019/001/')
filename = '19001.V3status'
local_filename = os.path.join(r"C:/path/where/download/files", filename) #example
lf = open(local_filename, "wb")
ftps.retrbinary('RETR ' + filename, lf.write)
file = "C:/path/where/download/files/" +filename #example
dataV3status = pd.read_fwf(file,
names = ('Mon_ID', 'Full_Mon_ID', 'RNX_Ver.', 'Dly(H)',
'Dly(M)', 'V', 'Receiver_Type', 'Antenna_Type',
'Mkr_Name', 'Marker_Number', 'Typ', 'G', 'R',
'E', 'C', 'J', 'S', 'I', 'MD5_Checksum'),
widths = [5,9,5,5,6,2,20,22,5,10,3,3,2,2,2,2,2,2,32],
header = None,
skiprows = 5,
skipfooter = 16)
推荐答案
如果你想坚持使用 ftplib,你可以这样做:
If you want to stick with ftplib, you can do something like this:
from io import BytesIO
flo = BytesIO()
ftp.retrbinary('RETR ' + filename, flo.write)
flo.seek(0)
pd.read_fwf(flo, ...)
这篇关于在 Python 中从 FTP 服务器读取文件到 DataFrame的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
织梦狗教程
本文标题为:在 Python 中从 FTP 服务器读取文件到 DataFrame


基础教程推荐
猜你喜欢
- 比较两个文本文件以找出差异并将它们输出到新的文本文件 2022-01-01
- 究竟什么是“容器"?在蟒蛇?(以及所有的 python 容器类型是什么?) 2022-01-01
- kivy 应用程序中的一个简单网页作为小部件 2022-01-01
- matplotlib 设置 yaxis 标签大小 2022-01-01
- 对多索引数据帧的列进行排序 2022-01-01
- Python 中是否有任何支持将长字符串转储为块文字或折叠块的 yaml 库? 2022-01-01
- 在 Django Admin 中使用内联 OneToOneField 2022-01-01
- 在 Python 中将货币解析为数字 2022-01-01
- Python,确定字符串是否应转换为 Int 或 Float 2022-01-01
- Kivy 使用 opencv.调整图像大小 2022-01-01