如何高亮显示数据帧中包含特定对象的所有单元格



我有以下数据帧:

德国亚美尼亚津巴布韦印度津巴布韦
位置 国家

看看熊猫的造型。您可以通过以下方式获得所需输出:

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)

最新更新