Hello everyone,
I’m new to Streamlit. I’ve searched other discussions but couldn’t find a solution.
I want to allow users to fill in data using the data_editor widget, download it as a CSV file, and then re-import it later to continue editing. The expected behavior is that any data entered directly in the editor should remain intact and be merged with the uploaded CSV file’s content, without altering the table structure.
However, I’m encountering the following issue:
When I try to modify a cell, my input initially disappears, and an unexpected empty column appears on the left:
After re-entering the value in the cell, it finally stays.
Here is the code:
import streamlit as st
import pandas as pd
st.title('Title')
if "df" not in st.session_state:
st.session_state.df = pd.DataFrame(columns=['name', 'year'])
st.download_button(
label="Download CSV",
data=st.session_state.df.to_csv(index=False).encode('utf-8'),
file_name="data.csv",
mime="text/csv",
)
uploaded_file=st.file_uploader(
label = "Upload a CSV file",
type="csv"
)
if uploaded_file is not None:
new_df = pd.read_csv(uploaded_file)
combined_df = pd.concat([st.session_state.df, new_df], ignore_index=True)
st.session_state.df = combined_df.drop_duplicates()
st.session_state.df=st.data_editor(
st.session_state.df,
column_config = {
'name' : st.column_config.TextColumn("name"),
'year' : st.column_config.NumberColumn("year")
},
num_rows='dynamic',
key="df_editor"
)
I’m using Streamlit 1.42.2 and Python 3.13.0 on Windows 10.
Thanks in advance!