我目前可以使用以下代码更改单元格的背景:
def my_func_blue(val):
if val in techniques:
color = 'green'
return f'background-color: {color}'
elif val in Fulltechniques:
color = 'red'
return f'background-color: {color}'
s = df1.style.applymap(my_func_blue)
s
我希望能够将另一个IF语句添加到
"if val in techniques"
因此,如果出现次数大于1,则应用颜色:
DF:
Technique_Name Technique_ID SOC Alarm Occurance
0 Sudo and Sudo Caching T1548.003 002 1
1 Elevated Execution with Prompt T1548.004 003 1
13 Cloud Account T1087.004 015 2
14 Cloud Account T1087.004 032 2
15 Account Manipulation T1098 016 1
因此,只有包含云帐户的单元格才会有绿色的背景色
如果逻辑更复杂,则可能链接多个条件,例如,此处
m1
与m2
用于创建样式的数据框架,如有必要,创建excel文件:相关问题 更多 >
编程相关推荐