0
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?

Henry Ecker
  • 34,399
  • 18
  • 41
  • 57
KickAxe
  • 149
  • 2
  • 13
  • Hi, kenken what is your IDE? – Isuru Dilshan Mar 26 '20 at 20:15
  • There is no error, the output of `df.style.applymap(color_negative_red)` is the object ``. This means that the variable `s` is not the DataFrame you are looking for, rather the `Styler` Object. – Philip Ciunkiewicz Mar 27 '20 at 01:04
  • Oh, thank you all for helping me. BTW @IsuruDilshan I use vscode version 1.43 – KickAxe Mar 27 '20 at 05:40
  • 2
    Does this answer your question? [Pandas Styler not printing dataframe to Spyder's console as expected](https://stackoverflow.com/questions/58116600/pandas-styler-not-printing-dataframe-to-spyders-console-as-expected) – Wai Ha Lee Mar 27 '20 at 11:41

1 Answers1

1

As mentions in this link, https://stackoverflow.com/a/58118375/7877099 Pandas styler is only supported in Jupyter notebook.

Isuru Dilshan
  • 719
  • 9
  • 18