My app has sliders in the left sidebar that allow the user to narrow down the range of various columns, then defines a
filt based on a long string of these sliders
My problem is when I attempt to show a multiselect box that has the Journal Name’s which meet that filter. If the user selects a Journal Name that is after a row that was removed by the filter, I get a KeyError.
In this example, the whole dataframe has 7 rows, of which indexes 3, 4, and 6 were filtered out. The multiselect box then shows the four remaining titles as options to choose. If I pick one of the first three, everything is fine. If I pick the fourth option (“Theoretical Computer Science”, corresponding to index 5), I get this error.
I have investigated the .loc operator in pandas and was able to make a working example in a Jupyter Notebook. I think this is traced down to the multiselect widget.
selected_titles = st.multiselect('Journal Name:', pd.Series(df.loc[filt, 'title']), help='Displayed in order provided by the underlying datafile')