【发布时间】:2019-04-11 17:45:06
【问题描述】:
Customer_id Name Age Balance
Q1 True True True
W2 True True True
E3 True False True
T5 True True False
Y6 True True True
U7 True True True
I8 False False False
O9 True False False
P0 False False False
我想在上面的数据框中用黄色突出显示或着色单词'TRUE'
这是我尝试过的代码:
def color_negative_red(val):
color = 'yellow' if val == 'TRUE' else 'black'
return 'color: %s' % color
df = dataframe.style.\
apply(color_negative_red).\
to_excel('df.xlsx')
我收到以下错误
ValueError: ('The truth value of a Series is ambiguous. Use a.empty, a.bool(), a.item(), a.any() or a.all().', 'occurred at index Customer_id')
我在这里做错了什么?
【问题讨论】:
标签: python pandas dataframe colors highlight