我有以下数据框comp
:
time first_max name second_max name.1 Perceived OoM.1 Perceived OoM.2
0 0.000000 18 shoulder_center 9 right_hip shoulder_center shoulder_center
1 0.010000 18 shoulder_center 9 right_hip shoulder_center shoulder_center
2 0.020000 18 right_hip 9 right_hip shoulder_center right_hip
3 0.030000 18 shoulder_center 9 right_hip shoulder_center right_hip
我有这个功能,根据name == Perceived OoM.1
是否突出显示整个行:
def highlight_col(x):
df = x.copy()
mask = df['name'] == df['Perceived OoM.1']
df.loc[mask, :] = 'background-color: yellow'
df.loc[~mask,:] = 'background-color: ""'
return df
comp.style.apply(highlight_col, axis=None)
但是,我想找出一种方法将name == Perceived OoM.2
涂满整个行。基本上,如果name == Perceived OoM.1
,我希望该行为黄色;否则,如果name == Perceived OoM.2
,我希望该行为蓝色。
但是我似乎无法将此条件应用到我的函数中。
有帮助吗?
答案 0 :(得分:2)
创建另一个掩码并以相同的方式传递,同样对于%run main.py
构造函数使用默认的空值:
DataFrame
答案 1 :(得分:1)