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.
After that, when you print a DataFrame, Pandas shows at most 20 rows before summarizing the rest.
A Simple Example
With that setting, Pandas prints a shortened view instead of flooding the console with all 100 rows.
If you want to see everything:
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:
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:
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.
Related Display Options
Row limits are often only part of the story. A few related options are commonly adjusted together:
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.
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:
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
Noneif 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

