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.sstatic.net/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?
As mentions in this link, https://stackoverflow.com/a/58118375/7877099 Pandas styler is only supported in Jupyter notebook.