Home > Enterprise >  Conditional Formatting Max and Min values along rows
Conditional Formatting Max and Min values along rows

Time:10-07

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
  1. I want the max value in every row to appear in green font and min value in every row to appear in red font.
  2. 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;'))

UPDATE
Based on d

  • Related