Saving a dataframe

Is there anyway to save a dataframe to my local pc? I’m trying to use:

if st.button(‘save dataframe’):

But nothing happens when I click the button.

1 Like

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']})

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?

1 Like

Ohhh, ok! That’s it, thanks!


Oh great! Apologies for the long delay in response. We’re working on it!

1 Like