I\'m using ipython notebook by connecting to a server I don\'t know how to download a thing (data frame, .csv file,... for example) programatically to my local computer. Because
Based on another answer, the following function will export a pandas data frame to a csv file and it will provide you with a link to download the csv file in your browser:
def csv_download_link(df, csv_file_name, delete_prompt=True):
"""Display a download link to load a data frame as csv from within a Jupyter notebook"""
df.to_csv(csv_file_name, index=False)
from IPython.display import FileLink
display(FileLink(csv_file_name))
if delete_prompt:
a = input('Press enter to delete the file after you have downloaded it.')
import os
os.remove(csv_file_name)
To get a link to a csv file, enter the above function and the code below in a jupyter notebook cell :
csv_download_link(df, 'df.csv')
By default the argument delete_prompt=True
makes sure that once you have downloaded the csv file, it gets deleted so the file doesn't pollute the git repository where you naturally archive your notebooks.