Skip to content

Instantly share code, notes, and snippets.

@MuLx10
Last active March 4, 2020 15:00
Show Gist options
  • Save MuLx10/0e1116585d5b0e8d1ff4b87cda77a73f to your computer and use it in GitHub Desktop.
Save MuLx10/0e1116585d5b0e8d1ff4b87cda77a73f to your computer and use it in GitHub Desktop.
Download Submission file from IPython notebook (Kaggle, Collab, etc.)
import base64
import pandas as pd
from IPython.display import HTML
def create_download_link( df, title = "Download CSV file", filename = "submission.csv"):
csv = df.to_csv(index = False)
b64 = base64.b64encode(csv.encode())
payload = b64.decode()
html = '<a download="{filename}" href="data:text/csv;base64,{payload}" target="_blank">{title}</a>'
html = html.format(payload=payload,title=title,filename=filename)
return HTML(html)
create_download_link(df)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment