Created
January 26, 2021 11:24
-
-
Save ahmedshahriar/4fd967d34ce19061ced9b160651ba910 to your computer and use it in GitHub Desktop.
The snippet has a function which takes pandas DataFrame as an argument and convert it to csv file and return an href link to download the csv
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 pandas as pd | |
import base64 | |
def download_dataset(dataset): | |
csv = dataset.to_csv(index=False) | |
b64 = base64.b64encode(csv.encode()).decode() # strings to bytes conversions | |
href_link = f'<a href="data:file/csv;base64,{b64}" download="player_stats.csv">Download CSV File</a>' | |
return href_link | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment