Is there anyway to save a dataframe to my local pc? Iām trying to use:
if st.button(āsave dataframeā):
df.to_csv('mydf.csv)
But nothing happens when I click the button.
Is there anyway to save a dataframe to my local pc? Iām trying to use:
if st.button(āsave dataframeā):
df.to_csv('mydf.csv)
But nothing happens when I click the button.
Hi @Okita,
As far as I can tell youāre just missing the āwriting to diskā part of the script that would accomplish what you want. I just tried this script and it worked ā it wrote ādf.csvā into the directory where streamlit was run when I pressed the button.
import streamlit as st
import pandas as pd
df = pd.DataFrame({'numbers': [1, 2, 3], 'colors': ['red', 'white', 'blue']})
st.write(df)
if st.button('save dataframe'):
open('df.csv', 'w').write(df.to_csv())
This is assuming that you are simply trying to write the CSV to disk.
Does this accomplish what you need?
Ohhh, ok! Thatās it, thanks!
Oh great! Apologies for the long delay in response. Weāre working on it!
Hi!
I just start working with streamlit but I think itās awesomeā¦ butā¦ I canāt find any more advanced funtion in documentatnion
And now I have a problem with save dataframe as file. I do everything like above:
if len(data_frame) == 0:
st.write("ProszÄ zaÅadowaÄ plik z osobnikami by uzyskaÄ wynik i wygenerowaÄ raport.")
else:
min = st.number_input('Od:', 0, len(data_frame), 0)
max = st.number_input('Do:', 0, len(data_frame), len(data_frame) )
dataset = st.container()
table = st.dataframe(data_frame.iloc[min:max])
if st.button('GENERUJ RAPORT DLA ZAKRESU'):
open('table', 'w').write(table.to_csv())
but I got:
StreamlitAPIException :
to_csv()
is not a valid Streamlit command.
So itās not working anymore in my example. How can I write that table as file?
Best regards!
P.S.
Sorry for refreshing old thread but I think itās a right place cos searching in internet solution, I got that link
These cookies are necessary for the website to function and cannot be switched off. They are usually only set in response to actions made by you which amount to a request for services, such as setting your privacy preferences, logging in or filling in forms.
These cookies allow us to count visits and traffic sources so we can measure and improve the performance of our site. They help us understand how visitors move around the site and which pages are most frequently visited.
These cookies are used to record your choices and settings, maintain your preferences over time and recognize you when you return to our website. These cookies help us to personalize our content for you and remember your preferences.
These cookies may be deployed to our site by our advertising partners to build a profile of your interest and provide you with content that is relevant to you, including showing you relevant ads on other websites.