Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in Python by (47.6k points)

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 colour-coding for the different columns.

1 Answer

0 votes
by (106k points)

For Pretty-printing an entire Pandas Series / DataFrame you can use the option_context, which has a feature of one or more options:-

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

print(df)

So option_context() will automatically return the options to their previous values.

Another thing you can do is follow the below mention way which is quite simple to use:-

print(df.to_string())

Related questions

0 votes
1 answer
0 votes
1 answer
0 votes
1 answer

Browse Categories

...