I have received answers to this about using Streamlit with DataFrame and Filter and I continue to struggle greatly. I think I may be too old to learn new things. Maybe there is a generous should out there that can help me get this organized. Been at it for a week.
The goal is here to display a Dataframe that can be filtered and can be updated on screen. My first attempt caused both the current DF and the filtered DF.
Here’s my latest attempt
query = 'SELECT Investor_Id, LastName, Distribution_date, Distribution_Year, ’
'Distribution_quarter, Distribution_Net ,Investment from ’
'Distribution, Investors ’
‘where Investors.InvestorID = Distribution.Investor_Id’
st.title(‘BDK Services Group’)
df = pd.read_sql(query, mydb)
nameList = df[‘LastName’].drop_duplicates()
yearList = df[‘Distribution_Year’].drop_duplicates()
quarterList = df[‘Distribution_quarter’].drop_duplicates()
investmentList = df[‘Investment’].drop_duplicates()
FilterInvestment = st.sidebar.selectbox(“Investment”, investmentList)
FilterLastName = st.sidebar.selectbox(“LastName”, nameList)
FilterYear = st.sidebar.multiselect(“Distribution_Year”,yearList)
FilterQuarter = st.sidebar.multiselect(“Distribution_Quarter”, quarterList)
st.button(“Create PDF”, key=“CreatePDF”)
df.loc[(df[‘Investment’] == FilterInvestment) & (df[‘LastName’] == FilterLastName)] &
(df[‘Distribution_Year’] == FilterYear) & (df[‘Distribution_Year’] == FilterYear)]
st.session_state
mydb.close() # close the connection