I have a dataframe that contains threshold values for 20+ elements that's formatted like so
df1:
Li | Se | Be | |
---|---|---|---|
Upper | 30 | 40 | 10 |
Lower | 10 | 5 | 1 |
I have another dataframe which contains values for those elements
df2:
Li | Se | Be | |
---|---|---|---|
Sample 1 | 50.8 | 100 | 20 |
Sample 2 | -0.01 | 2 | -1 |
If the values in df2 are greater than the Upper threshold I want the background color of the cell in df2 be to red when it is written to an excel file. If the value is lower than the lower threshold I want the cell to be colored yellow.
So in the example, 50.8 background color should be red because 50.8 > 30.
I've done this before when comparing a single value like so
df.style.apply(lambda x: 'background-color : red' if x>=value else '')
But I'm lost on how to apply it column wise based on the columns in df1