Download CSV from an iPython Notebook
Question: I run an iPython Notebook server, and would like users to be able to download
a pandas dataframe as a csv file so that they can use it in their own
environment. There's no personal data, so if the solution involves writing the
file at the server (which I can do) and then downloading that file, I'd be
happy with that.


Answer: How about using the Filelinks class from IPython? I use this to provide access
to data directly from Jupyter notebooks. Assuming your data is in pandas
dataframe p_df:

    
    
    from IPython.display import Filelink, FileLinks
    
    p_df.to_csv('/path/to/data.csv', index=False)
    p_df.to_excel('/path/to/data.xlsx', index=False)
    
    FileLinks('/path/to/')
    

Run this as a notebook cell and the result will be a list of links to files
downloadable directly from the notebook. `'/path/to'` needs to be accessible
for the notebook user of course.

