I’ve started working with streamlit & python very recently, this could be a very basic question and not sure if I can post it here or should use StackExchange for help. But any help or direction is appreciated.
Trying to filter dataframes to show different views. It involves selecting values from three dropdown values and one view without selecting any.
Each filter shows visualization for the filtered dataframe
def select_1(source_df: pd.DataFrame) -> pd.DataFrame: selected_mgr = st.multiselect( "Select Manager Name for further exploration below", source_df["manager"].unique(), ) selected_1_df = source_df[(source_df["manager"].isin(selected_mgr))] if selected_mgr: st.write('You have selected', selected_mgr) return selected_1_df def select_2(selected_1_df: pd.DataFrame) -> pd.DataFrame: selected_emp = st.multiselect( "Select Consultant Name for further exploration below", selected_1_df["employee"].unique(), ) selected_2_df = selected_1_df[(selected_1_df["employee"].isin(selected_emp))] if selected_emp: st.write('You have selected', selected_emp) return selected_2_df def select_3(selected_2_df) -> pd.DataFrame: selected_month = st.multiselect( "Select one or more Months for further exploration below", selected_2_df["month"].unique(), ) selected_3_df = selected_2_df[(selected_2_df["month"].isin(selected_month))] if selected_month: st.write('you have selected', selected_month) return selected_3_df source_df = df ## Calling functions for st.multiselect selected_1_df = select_1(source_df) selected_2_df = select_2(selected_1_df ) selected_3_df = select_3(selected_2_df ) if not selected_1_df.empty: do some stuff(selected_1_df) elif not selected_2_df.empty: do some stuff (selected_2_df) elif not selected_3_df.empty do some stuff (selected_3_df) else: do some stuff(source_df)
The problem I’m facing is, I’m unable to pass the first filtered dataframe to the next. Different approach or a solution to this also would help.