HiveBrain v1.2.0
Get Started
← Back to all entries
patternpythonCriticalCanonical

Pretty-print an entire Pandas Series / DataFrame

Submitted by: @import:stackoverflow-api··
0
Viewed 0 times
seriesentireprettydataframepandasprint

Problem

I work with Series and DataFrames on the terminal a lot. The default __repr__ for a Series returns a reduced sample, with some head and tail values, but the rest missing.

Is there a builtin way to pretty-print the entire Series / DataFrame? Ideally, it would support proper alignment, perhaps borders between columns, and maybe even color-coding for the different columns.

Solution

You can also use the option_context, with one or more options:

with pd.option_context('display.max_rows', None, 'display.max_columns', None):  # more options can be specified also
    print(df)


This will automatically return the options to their previous values.

If you are working on jupyter-notebook, using display(df) instead of print(df) will use jupyter rich display logic (like so).

Code Snippets

with pd.option_context('display.max_rows', None, 'display.max_columns', None):  # more options can be specified also
    print(df)

Context

Stack Overflow Q#19124601, score: 1597

Revisions (0)

No revisions yet.