【发布时间】:2022-01-09 15:23:59
【问题描述】:
我正在尝试从 FTP 的文件夹中读取 CSV 文件。该文件有 3072 行。但是,当我运行代码时,它并没有读取所有行。底部的某些行被遗漏了。
## FTP host name and credentials
ftp = ftplib.FTP('IP', 'username','password')
## Go to the required directory
ftp.cwd("Folder_Name")
names = ftp.nlst()
final_names= [line for line in names if '.csv' in line]
latest_time = None
latest_name = None
#os.chdir(filepath)
for name in final_names:
time1 = ftp.sendcmd("MDTM " + name)
if (latest_time is None) or (time1 > latest_time):
latest_name = name
latest_time = time1
file = open(latest_name, 'wb')
ftp.retrbinary('RETR '+ latest_name, file.write)
dat = pd.read_csv(latest_name)
要从 FTP 读取的 CSV 文件如下-
代码的输出是as-
【问题讨论】:
-
请不要张贴文字截图。相反,发布文本本身,formatted in a code-block
标签: python python-3.x pandas ftp ftplib