How to filter dataframe with multiple widgets

I have a dataframe that is retrieved from database and i am trying to do a filter firm where user can perform a custom search.

The form includes
Text input
Selectbox
Slider
Where each widjet search in one or more columns.

So the user can filter using one or more of these widgets.

The problem is that the result always is taking the values of 3 widgets and return a wrong answer.

In sql query
I can perform the below query and return the correct answer.

Select col1 col2
From table 1
Where name like '%james%' or nickname '%james%'
And job ='manager'

Without adding the third filter.

Where as in pandas it takes the also the third value from the slider regardless if the user choose it.

Hope that anyone can help me its urgent.

If you are able to post a code snippet others might be able to help more specifically.

One way to ignore that third value in your streamlit filtering code is to add checkboxes that determine whether or not to filter by that value. You can include this after a form submit or in a callback.

In this example all 3 data points still exist, but don’t get used based on the checkboxes.

import streamlit as st

with st.form("my_form"):
    use_name = st.checkbox("Use the Name to filter", value=True)
    use_nickname = st.checkbox("Use the Nickname to filter", value=True)
    use_job = st.checkbox("Use the Job to filter", value=True)

    name = st.text_input("Name?")
    nickname = st.selectbox("Nickname?", ("james", "jim", "jimmy"))
    job = st.slider("Job?", 1, 10)

    submitted = st.form_submit_button()

    if submitted:
        if use_name:
            st.write("Name: ", name)
        if use_nickname:
            st.write("Nickname: ", nickname)
        if use_job:
            st.write("Job: ", job)

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.