Why isn’t there any feature to pass columns as an argument in st.data_editor() so that they can be hidden in the dataframe to be displayed in the app UI, but still be present in the underlying dataframe in memory?
My current use-case:
I want to compare the flags that have been edited in a dataframe displayed using st.data_editor() and for this purpose, I’m merging the dF before edits with the dF after edits (not big of a dataFrame) on a common key column. But I do not want to necessarily display that column in the UI, since the keys don’t make any sense.
Is there any alternative or workaround to this?
Thanks in advance!
Welcome to the community and thanks for your thoughtful question!
Currently, Streamlit’s st.data_editor() does not have a direct parameter to hide columns while keeping them in the underlying DataFrame. However, you can control which columns are visible in the UI by using the column_order parameter—just pass a list of columns you want to display, and the rest will be hidden from the user but still present in your DataFrame. This approach is the recommended workaround for your use case, as confirmed in the Streamlit documentation and community discussions.
Here’s a quick example:
import streamlit as st
import pandas as pd
df = pd.DataFrame({
"key": [1, 2, 3],
"flag": [True, False, True],
"value": [10, 20, 30]
})
# Only show 'flag' and 'value' columns in the editor, hide 'key'
edited_df = st.data_editor(df, column_order=["flag", "value"])
This way, your ‘key’ column remains in the DataFrame for merging or comparison, but is not shown in the UI. For more details, see the official docs and community workaround.
Sources:
1 Like