How to save pandas dataframe to csv after click button?

Hello!
I’m starting use streamlit, and I love it… but I have one problem. I can’t save pandas as csv file. I found one solution on forum, but it’s not working anymore.
This is my code:

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'):
        table.to_csv(index=False)
       

And I got a Error:

StreamlitAPIException : to_csv() is not a valid Streamlit command.

Maybe someone here have a solution how to save that table to csv?

Streamlit, version 0.87.0

You need data_frame.to_csv(index=False)

1 Like

OMG… again the same. That moments when I hate programming. Spending hours to reading docs, trying another solution… and the problem is wrong variable passed to function… Dumb like coma ommiting :cactus:
Thank u very much! :smiley:

Happens to all of us :exploding_head: Happy Streamliting!