我有以下数据帧:
位置 | 国家 | 组 |
---|
看看熊猫的造型。您可以通过以下方式获得所需输出:
def zimbabwe_red(val):
color = 'red' if val == "Zimbabwe" else 'black'
return f"color: {color}"
df.style.applymap(zimbabwe_red)
def highlight(s):
'''
change the background color for a particular object in red.
'''
return ['background-color: red' if v == 'Zimbabwe' else '' for v in s]
df.style.apply(highlight)