Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
425 views
in Technique[技术] by (71.8m points)

python - Pandas Styler not printing dataframe to Spyder's console as expected

I am trying to output a pandas dataframe with colored cells to the console using the pandas Styler feature. When I run code examples in Spyder 3.2.6 running python 2.7, instead of seeing the dataframe as expected, the console outputs "...pandas.core.style.Styler at 0x1d0d7cf8>..."....this is what I would expect see with high-dimensional objects that ie need to be subset in order to view properly in the console

I've also tried calling .render() on the dataframe but this outputs a lot of unicode (?) text to console which is useless

I've also tried various examples from the Styler user guide with the same results (https://pandas.pydata.org/pandas-docs/stable/user_guide/style.html) and also the example from this post: Coloring Cells in Pandas

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

s = df.style.applymap(_color_red_or_green) 

s 

# and

s.render()

# example from pandas page:
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[0, 2] = np.nan

df.style

I expect to see my dataframe output with colored cell but only see:

<pandas.core.style.Styler at 0x1d0d7cf8>

what am I missing? perhaps my Spyder isn't set up to read unicode properly or something?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

(Spyder maintainer here) Pandas styler only works in the Jupyter notebook for now, not in Spyder.

Note: We have plans to support this in Spyder 6, to be released in 2022.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...