Hi to all
I have a small watchlist of stocks as a st.data_editor that i want to modify and save as a csv at a local directory at the end of every day and then reload it from there the next day when i restart my streamlit app.
I only need the part of the code or function that saves the table to csv to any assigned directory with a button or something similar.
Can someone help me to do this.
Many Thanks in advance!
watchlist = {
âLong Bottomâ: [âAAPLâ],
âLong Bottom Sqzâ: [âGOOGâ],
âShort Topâ : [âINTCâ],
âShort Top Sqzâ : [âNFLXâ],
âContinuation Longâ: [âGMâ],
âContinuation Shortâ: [âDISâ],
}
stox_list = pd.DataFrame(watchlist)
st.data_editor(stox_list,num_rows=âdynamicâ)
Hi ! You can refer this code below if maybe helpful.
import streamlit as st
import pandas as pd
df = pd.read_csv("dir/file.csv")
@st.experimental_memo
def convert_df(df):
return df.to_csv(index=False).encode('utf-8')
csv = convert_df(df)
st.download_button(
"Press to Download",
csv,
"file.csv",
"text/csv",
key='download-csv'
)
use .to_csv insted to excel
if you want your data to be exported into pure excel format then consider using other python lib like
open_xlsb
xlsxwriter
Any question ? plz be free to ask
Thanks a lotâŠi ll try the code and let you know asap!
Hi againâŠthe code just writes the existing data frame to csvâŠthe point is to edit the data frame with st.editor in my streamlit app and then update/rewrite the file in the directory so that next time i run the app it is going to load the updated csvâŠ