Last active
March 4, 2020 15:00
-
-
Save MuLx10/0e1116585d5b0e8d1ff4b87cda77a73f to your computer and use it in GitHub Desktop.
Download Submission file from IPython notebook (Kaggle, Collab, etc.)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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