I have a large dataframe (about 48,000 rows) that I want to filter through via user inputs to select boxes. I have my sidebar configured as shown below.
Is it possible in Streamlit to use those user inputs as filters through the dataframe and display the contents of a final dataframe column? I have 5 columns of data in my dataframe (4 of the columns are the inputs shown above). I want to show the last column in my dataframe on the main part of the page after filtering from the chosen inputs.
I always want to show all of the possible entries from the “makes” columns because that’s the initial start of the filtering. But after a selection is made in that column, I would like for the available selections to only be the filtered down “years” of that “make” and so on through each select box.
Also, is there a way to best optimize the loading of this data? Would it be best to load all of the data in the beginning and keep it in the cache or is would it be better to step-by-step load the data as the user makes selections?
Here’s my current, very simple code:
import streamlit as st import pandas as pd @st.cache def get_data(): path = r'cars.csv' return pd.read_csv(path) df = get_data() makes = df['make'].drop_duplicates() years = df['year'] models = df['model'] engines = df['engine'] components = df['components'] make_choice = st.sidebar.selectbox('Select your vehicle:', makes) year_choice = st.sidebar.selectbox('', years) model_choice = st.sidebar.selectbox('', models) engine_choice = st.sidebar.selectbox('', engines) st.write('Results:', components)