Topic starter 18/06/2021 12:36 pm
I would like to give the negative numbers in my 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?
Govind and myTechMint liked
27/06/2021 4:21 pm
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)