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

穿精又带淫゛_ 提交于 2021-02-13 17:38:14

问题


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?


回答1:


(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 5, to be released in 2020.



来源:https://stackoverflow.com/questions/58116600/pandas-styler-not-printing-dataframe-to-spyders-console-as-expected

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!