'Iterate over the mulstiselect widget and display dataframe for each item in python and streamlit?

i have a multiselect widget where the user select an item and the system display the dataframe related to the selected item.

What i need is each time the user select an item from the multiselect new dataframe is displayed so the output becomes:

  • if user select 2 items i will have 2 dataframe
  • if user select 4 items i will have 4 dataframe

until now it wrote this:

option_dept = df["dept"].unique().tolist()
selected_dept = st.multiselect("search by departement",option_dept)
if selected_dept:
  df = df[df["dept"].isin(selected_dept)].drop('count', axis=1).replace('NA', np.nan).dropna(axis=1)
  for i in selected_dept:
       st.write(df)

i know that i need to iterate over the multiselect list but i did not know how to do this .



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source