Skip to content

Instantly share code, notes, and snippets.

@ahmedshahriar
Created January 26, 2021 11:24
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 ahmedshahriar/4fd967d34ce19061ced9b160651ba910 to your computer and use it in GitHub Desktop.
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
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