how to show suggestions in st.text_input if we want to inport any value from dataframe.
for example if i have a dataframe which consist of fruit names and their colour. the first column is name of the fruit and second column is colour.
what i want to do is give name as st.text)input it shows suggestion as drop down box and then after choosing the name it shows me the corresponding color.
please help!!!
i know it is basic. sorry.

1 Like

No need to ever apologize on something being basic - we are all beginners at some point! In this case I think you can just use st.selectbox to do what you want; st.selectbox allows you to type in the box or to choose from a suggested drop down. Here’s some sample code of how you could use that. If just put your cursor in the box it will show you all of the dropdown items, but if you start typing ‘str’ it will filter down to suggest ‘strawberry and if you type in ‘apple’ it will say ‘no results’:

fruit = pd.DataFrame({
  'name': ['strawberry', 'pear', 'banana'],
  'colour': ['red', 'green', 'yellow']

selected_fruit = st.selectbox('Select a fruit', fruit['name'])
selected_colour = fruit[ == selected_fruit].iloc[0].loc['colour']

'The colour of a ', selected_fruit, ' is ', selected_colour

Let me know if that fixes your issue!


Hi @Shubham_Rathore. Great question. Thanks for asking.

1 Like

okay, i will remember that and yeah thank you, it worked. :grinning: