Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Pandas read data from a secure FTP server in Python 3

I am looking for a neat solution to read data (using either read_csv or read_sas) to a Pandas Dataframe from a secure FTP server in Python 3. All the examples I can find are many lines and some for Python 2. Isn't there a neat way to insert your username+password to Pandas read_csv-like method together with an ftp url and folder?

like image 455
rize Avatar asked Jun 27 '18 11:06

rize


1 Answers

pandas.read_csv() accepts a file-like object. Paramiko is a library which handles SFTP and can provide file-like objects. Once you've set up the connection, it's simple as:

with sftp.open("file.csv") as f:
    pd.read_csv(f)
like image 144
John Zwinck Avatar answered Nov 16 '22 08:11

John Zwinck