Pandas Styler 未按预期将数据帧打印到 Spyder 的控制台 [英] Pandas Styler not printing dataframe to Spyder's console as expected

查看:55
本文介绍了Pandas Styler 未按预期将数据帧打印到 Spyder 的控制台的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用 Pandas Styler 功能将带有彩色单元格的 Pandas 数据帧输出到控制台.当我在运行 python 2.7 的 Spyder 3.2.6 中运行代码示例时,控制台输出...pandas.core.style.Styler at 0x1d0d7cf8>..."...这就是我希望看到高维对象,即需要子集才能在控制台中正确查看

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

我也试过在数据帧上调用 .render() 但这会向控制台输出很多 unicode (?) 文本,这是无用的

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

我还尝试了 Styler 用户指南中的各种示例,结果相同(https://pandas.pydata.org/pandas-docs/stable/user_guide/style.html)以及这篇文章中的示例:Pandas 中的着色单元

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>

我错过了什么?也许我的 Spyder 没有设置为正确读取 unicode 之类的?

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

推荐答案

(Spyder 维护者在此)Pandas styler 目前仅适用于 Jupyter notebook,不适用于 Spyder.

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

注意:我们计划在 2021 年发布的 Spyder 6 中支持此功能.

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

这篇关于Pandas Styler 未按预期将数据帧打印到 Spyder 的控制台的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆