I would like to give the negative numbers in mine data frame a red color. But when trying to achieve with the following code
def color_negative_red(val):
"""
Takes a scalar and returns a string with
the css property `'color: red'` for negative
strings, black otherwise.
"""
color = 'red' if val < 0 else 'black'
return 'color: %s' % color
s = df05.style.applymap(color_negative_red)
print(s)
I got the following Value Error "ValueError: style is not supported for non-unique indices."
Where must i look to get the right output?
I believe you need unique default index values by DataFrame.reset_index
and drop=True
:
s = df05.reset_index(drop=True).style.applymap(color_negative_red)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With