Skip to content

Instantly share code, notes, and snippets.

@wesleyegberto
Created February 11, 2020 00:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save wesleyegberto/f0883b0390af33c1da4b5ef9f9b716d6 to your computer and use it in GitHub Desktop.
Save wesleyegberto/f0883b0390af33c1da4b5ef9f9b716d6 to your computer and use it in GitHub Desktop.
Function to download a Pandas dataframe from a Jupyter notebook
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)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment