【问题标题】:How to run pandas styler on mac terminal with highlighted dataframe如何使用突出显示的数据框在 mac 终端上运行 pandas styler
【发布时间】:2020-05-15 19:21:37
【问题描述】:

每当我在 jupyter notebook 上运行此代码时,它都会生成正确的突出显示数据框:

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)

def highlight_greaterthan(x):
    if x.C > .5:
        return ['background-color: yellow']*5
    else:
        return ['background-color: white']*5 
df.style.apply(highlight_greaterthan, axis=1)

但是,当我在我的 mac 终端中运行它时,我收到了以下输出:

<pandas.io.formats.style.Styler object at 0x118a6e198>

我想知道如何通过终端运行它并接收带有突出显示的数据框的输出。感谢您的帮助。

【问题讨论】:

    标签: python pandas macos terminal pandas-styles


    【解决方案1】:

    我相信这是由于 IDE。试试打印吧。

    【讨论】:

    • 打印它会产生相同的输出:。这是否意味着 pandas styler 只能在特定的 ide 中工作?看来我至少应该能够保存突出显示的数据框,但这似乎也不起作用
    猜你喜欢
    • 1970-01-01
    • 2020-05-08
    • 1970-01-01
    • 2010-11-22
    • 2022-08-19
    • 2022-10-02
    • 2018-03-26
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多