自定义样式熊猫数据框

时间:2017-12-04 13:42:44

标签: python python-3.x pandas dataframe

documentation显示了一个示例,介绍了如何根据值更改元素的字体颜色,这可以正常工作:

def color_negative_red(val):
    """
    Takes a scalar and returns a string with
    the css property `'color: red'` for negative
    strings, black otherwise.
    """
    color = 'red' if val < 0 else 'black'
    return 'color: %s' % color

s = df.style.applymap(color_negative_red)

我的问题是如何实现一个函数,而不是在整行中应用字体颜色变化?

1 个答案:

答案 0 :(得分:4)

您正在使用dbms.security.procedures.unrestricted=apoc.* ,因此如果行中的DataFrame至少有一个值,则将行设置为red

0