I have been struggling for months to get the Distribution Net column formatted as $$$ and I’ve failed at every attempt. It this a streamlit thing? Pandas thing?
Here’s the code:
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: DataFrame = pd.read_sql(query, mydb)
pd.options.display.float_format = ‘${:,.3f}’.format
nameList = df[‘LastName’].drop_duplicates()
yearList = df[‘Distribution_Year’].drop_duplicates()
quarterList = df[‘Distribution_quarter’].drop_duplicates().sort_values()
investmentList = df[‘Investment’].drop_duplicates()
FilterInvestment = st.sidebar.multiselect(“Investment”, investmentList)
FilterLastName = st.sidebar.selectbox(“LastName”, nameList)
FilterYear = st.sidebar.multiselect(“Distribution_Year”, yearList)
FilterQuarter = st.sidebar.multiselect(“Distribution_quarter”, quarterList)
print("Year : ", FilterYear)
print("Quarter : ", FilterQuarter)
print("Name : ", FilterLastName)
print("Investment : ", FilterInvestment)
filtered_df = df.loc[df[‘Investment’].isin(FilterInvestment) & (df[‘LastName’] == FilterLastName)]
styled_df = filtered_df.style.format({
‘Net’: ‘${:20,.0f}’, # Format as dollar amount with two decimal places
}).format({
‘Year’: lambda x: f"{x:.0f}" # Remove commas from years (treated as float/int)
})
Here are the results:
