-1
import pandas as pd
import numpy as np

np.random.seed(24)
df = pd.DataFrame({'A': np.linspace(1, 10, 10)})
df = pd.concat([df, pd.DataFrame(np.random.randn(10, 4), columns=list('BCDE'))],
               axis=1)
df.iloc[3, 3] = np.nan
df.iloc[0, 2] = np.nan

def color_negative_red(val):
    color = 'red' if val < 0 else 'black'
    return 'color: %s' % color

s = df.style.applymap(color_negative_red)
print(s)

The information output should be red when the data is less than 0:

https://i.stack.imgur.com/luv4M.png

But I keep getting the message below:

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

And I tried :

Styler.apply
Styler.applymap

I've got the same result as the error. How could I fix it?

4

1 回答 1

0

如此链接中所述,https: //stackoverflow.com/a/58118375/7877099 Pandas 样式器仅在 Jupyter 笔记本中受支持。

于 2020-03-26T20:29:41.147 回答