Filter existing dataframe based on checkboxes

def main():
    if "data" not in st.session_state: = {
            "person_locations": [],
            "organization_num_employees_ranges": [],
            "person_titles": [],
            "q_organization_keyword_tags": []

    page = st.sidebar.selectbox("Choose a page", ["Customize Parameters", "Results Page","Final Page"])

    if page == "Customize Parameters":
        st.title("Customize Parameters")

        # Person locations
        person_locations = st.multiselect("Select Person Locations", country_names,

        # Organization number of employees ranges
        organization_num_employees_ranges = st.multiselect("Select Organization Number of Employees Ranges",
                                                           ["1,10", "11,20", "21,50", "51,100", "101,200",
                                                            "201,500", "501,1000", "1001,2000", "2001,5000",
                                                            "5001,10000", "10001+"],

        # Person titles
        entered_titles = st.text_area("Enter Person Titles (comma-separated)",
                                      value=", ".join(["person_titles"]))
        person_titles = [title.strip() for title in entered_titles.split(",") if title.strip()]

        # Organization keyword tags
        q_organization_keyword_tags = st.text_input("Enter Organization Keywords (comma-separated)",
                                                    value=", ".join(["q_organization_keyword_tags"]))
        q_organization_keyword_tags = [tag.strip() for tag in q_organization_keyword_tags.split(",")]["person_locations"] = person_locations["organization_num_employees_ranges"] = organization_num_employees_ranges["person_titles"] = person_titles["q_organization_keyword_tags"] = q_organization_keyword_tags

        if st.button("Submit"):
            st.session_state.data_submitted = True
            st.success("Data submitted successfully!")
            st.markdown("[Go to Result Page](#result)")

    elif page == "Results Page":
        if "data_submitted" in st.session_state and st.session_state.data_submitted:
            st.title("Result Page")

            df = pd.DataFrame({
                'First Name': [person.get('first_name', '') for person in mde],
                'Last Name': [person.get('last_name', '') for person in mde],
                'LinkedIn URL': [person.get('linkedin_url', '') for person in mde],
                'Title': [person.get('title', '') for person in mde],
                'Headline': [person.get('headline', '') for person in mde],
                "Grab Emails?": False


            df, width=2000,
                "Grab Emails?": st.column_config.CheckboxColumn(
                    "Grab Emails?",
                    help="Tick to grab emails. This will consume 2 credit per email",
            disabled=["First Name","Last Name","LinkedIn URL","Title","Headline","Email"],
            hide_index=True, key = 'dfdata1'
             # Button to navigate to Final Page
            if st.button('Go to Final Page'):
       = "Final Page"
                st.experimental_rerun()  # Rerun the app to reflect the updated state       
            st.warning("Please submit the data first from the Customize Parameters page.")
    elif page == "Final Page":
        # Your Page 3 content goes here
        st.title("Final Page")
        st.write("Content of Final Page")

if __name__ == "__main__":

With regards to the dataframe df that I have on the Results Page, I would like to create another df below it that filters for rows in df where the checkbox in column โ€œGrab Emails?โ€ is ticked (i.e. TRUE).

How can I do this? I have tried to do df[df[โ€˜Grab Emails?โ€™]] but this doesnโ€™t generate any rows (i.e. it is saying there are no rows in the column that are TRUE).

I am running this script locally.

Hi @Bahir_Zaheri

How about df[df[โ€˜Grab Emails?โ€™]==True] where you also specify the condition in order to subset the data.

Also, please validate that some of the checkbox are ticked in order for the above statement to work.

df doesnโ€™t have your changes, they are in the data returned by data_editor.

Rookie mistake! I thought it might be something to do with the state but it was as simple as this^

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