I am trying to download a data frame from streamlit in the form of a csv file. However it is not able to download in the CSV form rather it is downloading in an object.I have to manually convert to csv to get my desire output.Below is the sample code:
import pandas as pd
import base64
import streamlit as st
X = pd.DataFrame({'A':["bad", "good", "better", "good", "better", "good", "better", "good", "better", "bad", "good", "better", "good", "better", "bad", "good", "better", "bad", "good", "better", "good", "better", "bad"],
'B': [3803, 1062, 4862, 6356, 2171, 532, 6982, 891, 1961, 3631, 1626, 1507, 3069, 2793, 721, 4288, 1601, 1439, 5807, 5054, 2411, 2913, 3505],
'C': [1318, 2537, 2315, 4967, 4483, 1433, 529, 1262, 1583, 506, 2576, 289, 3740, 3087, 309, 3493, 1862, 2666, 1231, 1828, 4144, 3503, 3102]
})
if X is not None:
csv_exp = X.to_csv(index=False)
b64 = base64.b64encode(csv_exp.encode()).decode() # some strings <-> bytes conversions necessary here
href = f'<a href="data:file/csv;base64,{b64}">Download Predicted File</a>(right-click and save as csv**)'
st.markdown(href, unsafe_allow_html=True)