pandas
data analysis
max rows
Python programming
data manipulation

Pandas max rows: set display.max_rows with pd.set_option

Codemia Knowledge Hub ·

Pandas does not always print every row of a DataFrame, because large outputs quickly become unreadable. The number of rows shown is controlled by display.max_rows, which you can set with pd.set_option, reset, or change temporarily for one block of code.

Setting display.max_rows

python
import pandas as pd

pd.set_option("display.max_rows", 20)

After this, printing a DataFrame shows at most 20 rows before summarizing the rest.

python
1import pandas as pd
2
3df = pd.DataFrame({"value": range(100)})
4
5pd.set_option("display.max_rows", 10)
6print(df)

Pandas prints a shortened view instead of flooding the console with all 100 rows. To show every row, use None, which disables row truncation:

python
pd.set_option("display.max_rows", None)
print(df)

Be careful with None on a huge DataFrame: printing it by accident can freeze or clutter your notebook or terminal.

Resetting to the default

python
pd.reset_option("display.max_rows")

This is useful in notebooks, because the option is global for the current Python process and a change in one cell affects later cells.

Temporary changes with option_context

pd.option_context changes the setting for one block only:

python
1import pandas as pd
2
3df = pd.DataFrame({"value": range(30)})
4
5with pd.option_context("display.max_rows", 8):
6    print(df)
7
8print("outside the context")
9print(df)

Inside the with block the temporary value applies, and the previous configuration is restored automatically afterwards. This is usually better than changing the global option and remembering to reset it.

If output still looks confusing, the cause may be column truncation or console width rather than the row limit. These options are often adjusted together:

python
1pd.set_option("display.max_rows", 20)
2pd.set_option("display.max_columns", 10)
3pd.set_option("display.width", 120)
4pd.set_option("display.max_colwidth", 50)

The same settings can also look different in Jupyter, VS Code notebooks and a terminal. Notebooks may render richer HTML output, while terminals rely on text width and wrapping, so if the result still looks odd after setting max_rows, check the environment's own display behavior too.

Display settings do not change the data

display.max_rows only affects how the DataFrame is displayed. It does not filter, slice or remove rows, so a truncated printout does not mean the DataFrame itself was shortened. Here it still contains all 1000 rows:

python
1import pandas as pd
2
3df = pd.DataFrame({"value": range(1000)})
4pd.set_option("display.max_rows", 5)
5
6print(len(df))  # 1000

Use head() and tail() for a quick look

For a one-off inspection, changing global display options is often unnecessary. head() and tail() are clearer:

python
print(df.head(10))
print(df.tail(10))

This keeps your environment stable and makes the intent of the code obvious. If you need a different view only once, head(), tail() or option_context are all better than a permanent global change.


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