[Python] Is it possible to display pandas styles in the IPython console?

Discussão em 'Python' iniciado por Stack, Dezembro 6, 2024.

  1. Stack

    Stack Membro Participativo

    Is it possible to display pandas styles in an iPython console? The following code in a Jupyter notebook

    import pandas as pd
    import numpy as np

    np.random.seed(24)
    df = pd.DataFrame({'A': np.linspace(1, 10, 5)})
    df = pd.concat([df, pd.DataFrame(np.random.randn(5, 1), columns=list('B'))],
    axis=1)
    df.style.format({'B': "{:.2%}"})


    correctly produces

    [​IMG]

    In the console I only get

    In [294]: df.style.format({'B': "{:.2%}"})
    Out[294]: <pandas.io.formats.style.Styler at 0x22f3f4fe780>


    Is it possible to achieve a similar result here, or is the style engine dependent on an html frontend?

    Thanks in advance for any help.

    Continue reading...

Compartilhe esta Página