Read FTP file contents in Python and use it at the same time for Pandas and directly

前端 未结 2 1868
甜味超标
甜味超标 2021-01-14 21:42

I am trying to download a file from an FTP server in memory, transform it to a dataframe but also return it as bytes. Code as follows:

import io
import panda         


        
相关标签:
2条回答
  • 2021-01-14 21:43

    read_csv probably closes the "file". So read it before you call read_csv:

    download_file.seek(0)
    contents = download_file.read()
    download_file.seek(0)
    file_to_process = pd.read_csv(download_file, engine='python')
    
    0 讨论(0)
  • 2021-01-14 21:57

    I think that's easier with tentaclio package :

    with tentaclio.open("ftp://user:password@host/path/name_file.csv") as reader:
        df = pd.read_csv(reader)
    
    0 讨论(0)
提交回复
热议问题