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: