I see that you can change a column type to categorical to render a dropdown but that takes only the values currently in the column. Is there a way to pass a custom list of values that is shown as dropdown options for a column?
Could you post a minimal example code?
You can add additional values to the dropdown - see here. Not sure if you can remove existing options though.
1 Like
Try the remove_categories method.
import pandas as pd
import streamlit as st
df = pd.DataFrame(
[
{"command": "st.selectbox", "rating": 4, "is_widget": True},
{"command": "st.balloons", "rating": 5, "is_widget": False},
{"command": "st.time_input", "rating": 3, "is_widget": True},
]
)
custom_cat = ['aaa', 'bbb']
df["command_as_category"] = (
df["command"].astype("category").cat.remove_categories(df['command']).cat.add_categories(custom_cat)
)
edited_df = st.experimental_data_editor(df)
I donβt want to create new column. Iβd like the dropdown to shown for an existing column. I.e in the above code for command column. Is it possible?
Yes
Just change command_as_category
to command
.
1 Like