I want to highlight the maximum value in each row as green and the minimum value as red.
import numpy as np import pandas as pd value = np.random.normal(size=(5,5)) #Generate random data df = pd.DataFrame(value) display(df.style.highlight_max(color = 'lightgreen', axis = 1)) # This works for max part display(df.style.highlight_min(color = 'red', axis = 1)) # This also works for min part
But combining those 2 code like this :
df.style.highlight_min(color = 'red', axis = 1).style.highlight_max(color = 'lightgreen', axis = 1)
give me this error
AttributeError: 'Styler' object has no attribute 'style'
What is the correct way to use both of them? Thanks
Advertisement
Answer
And it turns out that I don’t need to call another style attribute. Will leave this for future readers who have the same problem with me :)
df.style.highlight_min(color = 'red', axis = 1).highlight_max(color = 'lightgreen', axis = 1)
will work.