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.
You can pretty print pandas dataframe using pd. set_option('display. max_columns', None) statement. Usecase: Your dataframe may contain many columns and when you print it normally, you'll only see few columns.
Method 2: Using set_option() display. max_rows represents the maximum number of rows that pandas will display while displaying a data frame. The default value of max_rows is 10. If set to 'None' then it means all rows of the data frame.
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).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With