Created
November 18, 2017 13:18
-
-
Save HaiyangXu/ef0a6ad1eb468365b050812196e5b6a4 to your computer and use it in GitHub Desktop.
Download CSV file from data frame in jupyter
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
from IPython.display import HTML | |
import base64 | |
import pandas as pd | |
def create_download_link( df, title = "Download CSV file", filename = "data.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