How can I filter a dataframe using a selectbox?
Steps to reproduce
# UNIQUE LISTS FOR MULTISELECT OPTIONS
calc_type_unique = df_all_data['Calc Type'].unique().tolist()
type_unique = df_all_data['Type'].unique().tolist()
priority_unique = df_all_data['Priority'].unique().tolist()
scheme_unique = df_all_data['Scheme'].unique().tolist()
# SIDEBAR
st.sidebar.header("Select options from below:")
calc_type_selection = st.sidebar.selectbox('Calc Type:', calc_type_unique)
type_selection = st.sidebar.multiselect('Type:', type_unique, default=type_unique)
priority_selection = st.sidebar.multiselect('Priority:', priority_unique, default=priority_unique)
scheme_selection = st.sidebar.multiselect('Scheme:', scheme_unique, default=scheme_unique)
# CREATE MASK DEPENDING ON USER INPUT
mask = (df_all_data['Calc Type'].isin(calc_type_selection)) & (df_all_data['Type'].isin(type_selection)) & (df_all_data['Priority'].isin(priority_selection)) & (df_all_data['Scheme'].isin(scheme_selection))
I’m trying to create a mask but the isin for calc_type_selection errors with:
TypeError: only list-like objects are allowed to be passed to isin(), you passed a [str]
Traceback:
File "C:\Users\\Python\Python310\lib\site-packages\streamlit\runtime\scriptrunner\script_runner.py", line 565, in _run_script
exec(code, module.__dict__)File "C:\projects\GIT\2_Backlog.py", line 73, in <module>
mask = (df_all_data['Calc Type'].isin(calc_type_selection)) & (df_all_data['Type'].isin(type_selection)) & \File "C:\Users\\Python\Python310\lib\site-packages\pandas\core\series.py", line 5563, in isin
result = algorithms.isin(self._values, values)File "C:\Users\aahmed\Python\Python310\lib\site-packages\pandas\core\algorithms.py", line 459, in isin
raise TypeError(