Filter dataframe based on multiple criteria

Hello guys,
Newbie here
I have to filter my dataframe based on 4 criteria (maximum)
here is the script:
st.dataframe(df[a & b & c & d])

for a,b,c and d
the value is from this kind of script:
a = df["Col_a"].isin([such_criteria])

Anyway i am confuse to modify this script:
st.dataframe(df[a & b & c & d])

because the criteria is not always 4, sometimes the user have to choose only 1, 2 or 3 (with different combinations)
Please help, what kind of script to do that
Thank you

1 Like

Hi @arri! Good to see you back on the forum! :raised_hands:

Are you looking to dynamically amend the criteria list via st.multiselect? e.g.:

multiselect01 = st.multiselect('Multiselect', ["criterion_1","criterion_2","criterion_3"])

If so, what about adding the multiselect01 variable to isin , as follows:

a = df["Col_a"].isin([multiselect01])

Let me know if that’d work for you.


1 Like

Hello Charly,
Thank you for your reply
It works

1 Like

Glad to hear this @arri! :raised_hands:

Happy Streamlitin’!:balloon: