[Python] What condition determines whether prettyprint (%pprint) prints a list vertically?...

Discussão em 'Python' iniciado por Stack, Junho 9, 2025.

  1. Stack

    Stack Membro Participativo

    In Spyder, list(pd.DataFrame(range(22)).index) causes row numbers to print horizontally but list(pd.DataFrame(range(23)).index) causes row numbers to print vertically. There is still plenty of horizontal. What determines the threshold for switching the orientation of the print out?

    This Q&A was proposed as a duplicate, but it seems to seems to deal with text wrapping, not whether a Series is printed in horizontal or vertical orientation.

    >>> list(pd.DataFrame(range(22)).index)
    Out[74]: [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21]

    >>> list(pd.DataFrame(range(23)).index)
    [0,
    1,
    2,
    <...snip...>
    21,
    22]


    Issuing pd.get_option('display.width') confirms the default value of 80, but pd.set_option('display.width',100) does not avoid the vertical printout above, even after disabling and re-enabling %pprint.

    Continue reading...

Compartilhe esta Página