Hey everyone,
I’m facing the following issue:
When displaying the dataframe initially, everything is displayed as expected. After typing e.g. ‘abc’ into the text field, the dataframe is filtered correctly and the result is shown. When displaying the filtered dataframe, the index of the dataframe is shown as a data editor column (despite having it hidden, it’s even editable). Why does that behavior occur?
My code snippet (this snippet is just for demonstration purpose and doesn’t work completely):
import pandas as pd
import streamlit as st
from streamlit import session_state as ss
def get_df():
data_dict = {'col1': [], 'col2': []}
for i in range (0, 20):
if i == 5:
data_dict['col1'].append("abcd")
else:
data_dict['col1'].append("ab")
data_dict['col2'].append("vf")
df = pd.DataFrame(data_dict)
df.insert(2, 'Active', True)
return df
if 'df' not in ss:
ss.df = get_df()
name = st.text_input('Search for ...',key='filter',help='Case insensitive search. Not submitted data are discarded')
if name == '':
ss.df.Active = True
ss.df = get_df()
else:
ss.df.Active = False
ss.df.loc[ss.df['col1'].str.contains(name, case=False), 'Active'] = True
ss.df = ss.df[ss.df['Active'] == True]
print("ss.df:")
print(ss.df)
df_ed=st.data_editor(ss.df, hide_index=True,use_container_width=True
,column_order=('col1', 'col2')
,disabled=['col1', 'col2']
,key='editor')
I’m using
- Streamlit 1.30.0
- Python 3.9.17
- pandas 2.0.3
Thank you!