如何通过比较两列来颜色熊猫表



例如,我有一个带有两个A和B的数据框。如果a< = b,我想为那排绿色上色。知道我该怎么做?谢谢!

来自文档:

def highlight_greater(row):
    if row['A'] > row['B']:
        color = 'red'
    elif row['A'] <= row['B']:
        color = 'green'
    background = ['background-color: {}'.format(color) for _ in row]
    return background
df.style.apply(highlight_greater, axis=1)

最新更新