如何渲染 Pandas df,其中列的style.bar.color
属性之一是根据某些条件计算的?
例子:
df.style.bar(subset=['before', 'after'], color='#ff781c', vmin=0.0, vmax=1.0)
我不想让两列都用 突出显示#ff781c
,我希望其中一列 ( df['before']
) 保持相同的恒定颜色,而另一列 ( df['after']
) 计算为:
def compute_color(row):
if row['after'] >= row['before']:
return 'red'
else:
return 'green