Sep-26-2023, 11:53 PM
(This post was last modified: Sep-26-2023, 11:53 PM by deanhystad.)
How about something like this:
It is difficult to know if this is a good fit for what you are trying to accomplish, because I really don't understand your code. You provide such narrow view, focusing on something that I don't think you even need to do. Could you explain what your program is supposed to do? Why would somebody use your code? What steps would the follow to produce the results they want, and what are those results?
for column in df: choices = set(df[column].values) if len(choices) < 2: continue choices = st.sidebar.multiselect(f"Pick your {column}", sorted(choices)) if choices: df = df[df[column].isin(choices)]This loops through every column. If there is more than one value to choose from in the column, it does the sidebar thing to get the user selections. If the user makes a selection, the selection is applied to the dataframe, removing the non-matching rows.
It is difficult to know if this is a good fit for what you are trying to accomplish, because I really don't understand your code. You provide such narrow view, focusing on something that I don't think you even need to do. Could you explain what your program is supposed to do? Why would somebody use your code? What steps would the follow to produce the results they want, and what are those results?