Hi all,
I’ve run into a problem when using st.data_editor
to edit a Pandas DataFrame with a custom index. This code should reproduce the issue:
import streamlit as st import pandas as pd import numpy as np import matplotlib.pyplot as plt # Initialize df if "df" not in st.session_state: index = [f"point_{i}" for i in range(10)] st.session_state.df = pd.DataFrame({ "x": np.arange(10), "y": np.random.randn(10) }, index=index) # Data editor edited_df = st.data_editor( st.session_state.df, key="editor_key", num_rows="dynamic", use_container_width=True, ) # Plot the result st.subheader("Live-updated Plot") fig, ax = plt.subplots() ax.plot(edited_df["x"], edited_df["y"], marker='o') ax.set_xlabel("x") ax.set_ylabel("y") ax.grid(True) st.pyplot(fig)
For example, if you delete some rows and then proceed to rename the index entries, the deleted rows are unexpectedly restored, and the index changes are not properly registered.
I wonder if this is the expected behavior — perhaps modifying the index directly is not supported?
Kind regards,