Multiple select boxes don't filter the dataframe

Hi! I have a problem with the code below. It only filters the and then when selecting the st.selectboxes the dataframe appears in white only the header. I don’t know where the error is. Whether it’s code or editor configuration. I use VSCode.

df = pd.read_csv(r"C:\Users\", sep=";")

with st.sidebar:

    product_list = list(df["Product"].unique())
    product ="SELECT THE PRODUCT", options=product_list)

    region_list = list(df["Region"].unique())
    region = st.selectbox(label="SELECT THE REGION", options=region_list)
    state_list = list(df["State"].unique())
    state = st.selectbox(label="SELECT THE STATE", options=state_list)
    city_list = list(df["City"].unique())
    city = st.selectbox(label="SELECT THE CITY", options=city_list)

    reset_filter = st.sidebar.button("RESET FILTERS") #not finished yet

query = f"Product =='{product}' & Region =='{region}' & State =='{state}' & City =='{city}'"
df_filter = df.query(query)

I tested your code with dummy data and it seems to be working fine.

My guess is, the problem can be one of the following

  • You have all filters filtering at once. Maybe you want to add a default value at the begining of every list of the options so that you have the option to filter with one column at a time.
  • Maybe there are spaces between your columns in addition to “;”.

These are just guesses, if you could share more info about your data, the problem would be easier to identify.

1 Like

Yes. It was all filters filtering at once!