熊猫样式数据框

时间:2020-01-06 09:04:28

标签: python pandas

我有以下熊猫数据框report

                 A          B              C                   D                E                 F
BCH      -1.640769       5.462205      8.438435e+04         9.777733e+02   5.452427e+05       2.365988e+07  
BTC            NaN       5.443305      2.944742e+04         2.241470e+03   5.420890e+05       1.793774e+09 
ETH            NaN       3.274849      6.498000e+05         3.243352e+04   3.242415e+06       4.772602e+08 
QASH           NaN       1.050000      2.538948e+04         3.163344e+07   -2.113344e+07       1.576178e+08
XRP            NaN       1.300137      5.865422e+07         8.843813e+06   1.291293e+09       1.867275e+08

我想对负数应用一种样式。为此,我使用以下代码。

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 = report.style.applymap(color_negative_red)

输出:

<pandas.io.formats.style.Styler object at 0x11cab0898>

因此,我没有任何错误,但是数据框没有印有红色数字。任何贡献将不胜感激。

0 个答案:

没有答案