How to print an entire pandas DataFrame or Series
Codemia Knowledge Hub ·
To print an entire pandas DataFrame or Series without truncation, use print(df.to_string()). For normal print(df) or notebook output, raise the display limits with pd.set_option('display.max_rows', None) and pd.set_option('display.max_columns', None), or apply them temporarily with pd.option_context.
Why pandas truncates output
pandas shortens large Series and DataFrame displays so interactive sessions stay readable. That gets in the way when you need to see every row or column:
For large objects, pandas may replace the middle with ellipses instead of printing everything.
Printing everything with to_string()
to_string() is the most direct fix:
It works the same way for a Series:
This is the safest choice in scripts because it bypasses most display truncation rules. Pass index=False when the index is just noise.
Changing display options
To make print(df) or notebook display show more rows and columns, change the display options:
These settings are global for the current Python process, so they also affect every later output.
Temporary changes with option_context
option_context applies the settings only inside a with block, which is cleaner for debugging or one-off reports:
Formatting floats
Readable output is also about formatting. For example, cleaner float formatting:
This helps when scientific notation or too many decimals make a table hard to scan.
Notebook styling is not console printing
In Jupyter, DataFrame.style improves visual presentation:
That suits notebooks and reports. For a plain text dump in logs or scripts, to_string() is still the better tool.
When the DataFrame is too big to print
Printing a huge DataFrame floods the terminal, notebook or logs. With millions of rows, printing everything is usually the wrong debugging strategy. Better options:
df.head()anddf.tail()df.sample()- exporting to a file with
to_csv - filtering to the rows you actually need
Printing the whole object is only useful while it is still small enough for a person to read.
Related reading
- Pretty Printing a pandas dataframe
- Principal Component Analysis in MATLAB
- Principal Component Analysis PCA on huge sparse dataset
- Principle of setting 'hash_bucket_size' parameter?
- Pretty-Print JSON Data to a File using Python
- Pretty printing XML in Python
- Print top 10 users who post lots of questions and lots of answers of a Web Forum
- Print very long string in Pandas dataframe
System design interview problems on this topic
- Design a Web Crawler: solution and walkthrough
- Design a Task Scheduler: solution and walkthrough
- Design a URL Shortener (TinyURL): solution and walkthrough
- Design an API Rate Limiter: solution and walkthrough
.png&w=3840&q=75)
Tackling System Design Interview Problems
A short course that equips you with the skills to approach system design interviews methodically.
Start the free courseNo course covers this one yet
Basis Lab writes one for you from a sentence about what you want to be able to do, then teaches it and checks you understood. Your first course is free.
Build my courseML System Design practice on Codemia
Design recommenders, ranking systems and training pipelines the way ML interviews actually ask for them, with worked solutions.