I have a table similar to below:
Sector | 4/1/2022 | 5/1/2022 | 6/1/2022 |
---|---|---|---|
A | 0 | 05 | 12 |
B | 18 | 20 | 09 |
C | 02 | 09 | 12 |
- I want the max value in every row to appear in green font and min value in every row to appear in red font.
- While calculating the min, I want to exclude 0 from the calculation.
I tried using the below code however it highlights the cell instead of changing font colour.
df.style.highlight_min(color = 'red', axis = 1)
CodePudding user response:
Try this:
(df.iloc[:,1:].style.highlight_max(axis=1, props='color:green;')
.highlight_min(axis=1, props='color:red;'))
# or
(df.set_index('Sector').style.highlight_max(axis=1, props='color:green;')
.highlight_min(axis=1, props='color:red;'))