awacke1's picture
Create app.py
1b7f935 verified
raw
history blame
997 Bytes
import base64
import pandas as pd
# Example DataFrame
data = {'Column1': [1, 2], 'Column2': [3, 4]}
df = pd.DataFrame(data)
# Function to convert DataFrame to CSV and then encode to base64
def to_base64_csv(df):
csv = df.to_csv(index=False)
b64 = base64.b64encode(csv.encode()).decode()
return f"data:text/csv;base64,{b64}"
# Function to convert DataFrame to TXT and then encode to base64
def to_base64_txt(df):
txt = df.to_csv(index=False, sep='\t')
b64 = base64.b64encode(txt.encode()).decode()
return f"data:text/plain;base64,{b64}"
# Generate base64 encoded links
csv_link = to_base64_csv(df)
txt_link = to_base64_txt(df)
# Markdown format for hyperlinks in bold font with emojis
markdown_csv_link = f"**[πŸ“₯ Download Dataset as CSV]({csv_link})**"
markdown_txt_link = f"**[πŸ“₯ Download Dataset as TXT]({txt_link})**"
# Display as markdown (hypothetical, depends on how you render markdown in your application)
print(markdown_csv_link)
print(markdown_txt_link)