I want to highlight cells if they are greater than a value dependent on the column header.
I want to 'read' the column header, if it is in the dictionary (CEPA_FW) then the corresponding value is returned. Then if any cells in that column are greater than this value, they are filled dark orange. My effort is below, but I am getting errors (ValueError: Length mismatch: Expected axis has 1 elements, new values have 4 elements).
df=pd.DataFrame(({'As':['0.001', 0, '0.001','0.06'], 'Zn': ['6','4','6','8'], 'Pb': ['0.006','0','0.005','0.005'], 'Yt': [1,0,0.002,6]}))
cols=df.columns
CEPA_FW= {'Ag':0.05,'As' :0.05 ,'Ba':1.0,'B':1.0,'Cd' :0.01 ,'Cr' :0.05 ,'Co':0.001,'Cu' :1.0 ,'K':5.0,'Pb' :0.005 ,'Hg' :0.0002 ,'Mn':0.5,'Ni' :1.0 ,'Se':0.01,'Sn':0.5,'SO4':400.0,'Zn' :5.0}
def fill_exceedances(val):
for header in cols:
if header in CEPA_FW:
for c in df[header]:
fill = 'darkorange' if c> CEPA_FW[header] else ''
return ['backgroundcolor: %s' % fill]
df.style.apply(fill_exceedances, axis = 1).to_excel('styled.xlsx', engine='openpyxl')

appropriate limit is returnedwhat do you mean by this?