pandas
data analysis
max rows
Python programming
data manipulation

Pandas Setting no. of max rows

Master System Design with Codemia

Enhance your system design skills with over 120 practice problems, detailed solutions, and hands-on exercises.

Introduction

Pandas does not always print every row of a DataFrame, because large outputs quickly become unreadable. The display behavior is controlled by options such as display.max_rows, which you can set globally, reset, or change temporarily for a single block of code.

The Main Setting: display.max_rows

To control how many rows Pandas prints before truncating the output, use pd.set_option.

python
import pandas as pd

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

After that, when you print a DataFrame, Pandas shows at most 20 rows before summarizing the rest.

A Simple Example

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

With that setting, Pandas prints a shortened view instead of flooding the console with all 100 rows.

If you want to see everything:

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

Using None tells Pandas not to truncate rows for display.

Reset Back to Default

If you changed the option and want Pandas to return to its default behavior, reset it:

python
pd.reset_option("display.max_rows")

This is useful in notebooks where display settings tend to persist longer than intended.

Temporary Changes with option_context

A very clean way to adjust the setting for one specific block is pd.option_context:

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, Pandas uses the temporary value. Outside it, the previous configuration is restored automatically.

This is often better than changing the global option and trying to remember to reset it later.

Row limits are often only part of the story. A few related options are commonly 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)

If output still looks confusing, the problem may be column truncation or console width rather than the row limit itself.

Display Settings Do Not Change the Data

This is an important distinction: display.max_rows only changes how the DataFrame is displayed. It does not filter, slice, or remove any rows from the actual data.

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

The DataFrame still contains all 1000 rows.

Prefer head() and tail() for Quick Inspection

Sometimes changing global display options is unnecessary. If you only want a quick look, head() and tail() are usually clearer:

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

That keeps your environment stable and makes the code's intent obvious.

Notebook Versus Terminal Behavior

The same display setting can feel different in Jupyter, VS Code notebooks, or a terminal. Notebooks may render DataFrames with 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.

Common Pitfalls

The biggest pitfall is setting display.max_rows to None on a huge DataFrame and then printing it accidentally. That can freeze or clutter your notebook or terminal.

Another pitfall is forgetting that the option is global for the current Python process. A change made in one notebook cell can affect later cells unexpectedly.

A third pitfall is assuming row truncation means the DataFrame itself is shortened. Display options do not modify the underlying data.

Finally, if you only need to inspect part of the data once, prefer head(), tail(), or option_context over permanent global changes.

Summary

  • Use pd.set_option("display.max_rows", n) to control how many rows Pandas prints
  • Use None if you want Pandas to display all rows
  • Reset the setting with pd.reset_option("display.max_rows")
  • Use pd.option_context(...) for temporary display changes
  • Remember that display settings affect rendering only, not the DataFrame contents

Course illustration
Course illustration

All Rights Reserved.