I am coding an app in Python using Streamlit and I would like to color code DataFrame cells across all columns if their values are greater than the value provided by another function.
The example code provided properly highlights cell values if they are higher than 80. How would I modify the .style.applymap(color) code to allow it to accept another argument to color the cells based on the value provided by the function net_60_comp? Is is possible to add n_value as an argument to make this possible?
Example Chart
def net_60_comp(amount,f_rate=0.043):
dis_to_60 = amount * ((1+f_rate)**(60/365)-1)
dis_perc_to_60 = dis_to_60/amount
return(dis_to_60,dis_perc_to_60)
def color (val):
v = net_60_comp
color = 'green' if int(val) > 80 else 'red'
return f'background-color: {color}'
st.sidebar.header("Change Inputs Here")
contract = st.sidebar.number_input("Please input yearly contract value")
d_amt = st.sidebar.number_input("Please input the contract discount amount")
choice = st.sidebar.radio("Payment Terms Calculator Function",r_sel,horizontal=True)
spec_days = st.sidebar.number_input("Please input the number of days for the special terms")
submit_button = st.sidebar.button("Calculate")
#Create a blank dataframe for the function results
if submit_button:
if choice == "Standard":
st.header("Discount Matrix", divider = "rainbow")
chart_data2 = annual_compare(contract)
n_value = net_60_comp(contract)
st.write(chart_data2.style.applymap(color))
#Create Discount Matrix Tab
st.header("Single-Year Matix", divider = "rainbow")
chart_data = calc(contract,d_amt)
st.write(chart_data)