Pandas
Data Science
Python
Data Analysis
Data Visualization

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:

python
1import pandas as pd
2
3s = pd.Series(range(30))
4print(s)

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:

python
1import pandas as pd
2
3df = pd.DataFrame({
4    'name': ['Ada', 'Linus', 'Grace'],
5    'age': [36, 42, 50],
6    'city': ['London', 'Helsinki', 'New York']
7})
8
9print(df.to_string(index=False))

It works the same way for a Series:

python
1import pandas as pd
2
3s = pd.Series(['apple', 'banana', 'cherry'])
4print(s.to_string(index=False))

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:

python
1import pandas as pd
2
3pd.set_option('display.max_rows', None)
4pd.set_option('display.max_columns', None)
5pd.set_option('display.width', None)
6pd.set_option('display.max_colwidth', None)

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:

python
1import pandas as pd
2
3df = pd.DataFrame({'x': range(100), 'y': range(100, 200)})
4
5with pd.option_context(
6    'display.max_rows', None,
7    'display.max_columns', None,
8    'display.width', None
9):
10    print(df)

Formatting floats

Readable output is also about formatting. For example, cleaner float formatting:

python
1import pandas as pd
2
3pd.set_option('display.float_format', '{:,.2f}'.format)
4
5df = pd.DataFrame({'value': [1234.5678, 98765.4321]})
6print(df)

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:

python
1import pandas as pd
2
3df = pd.DataFrame({'score': [91, 85, 99]})
4styled = df.style.format({'score': '{:.1f}'})
5styled

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() and df.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.


Free course
Beginner
7 lessons
2 hours
Tackling System Design Interview Problems

A short course that equips you with the skills to approach system design interviews methodically.

Start the free course
Basis Lab
No 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 course
ML System Design practice on Codemia

Design recommenders, ranking systems and training pipelines the way ML interviews actually ask for them, with worked solutions.

Practice ML system design