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
After this, printing a DataFrame shows at most 20 rows before summarizing the rest.
Pandas prints a shortened view instead of flooding the console with all 100 rows. To show every row, use None, which disables row truncation:
Be careful with None on a huge DataFrame: printing it by accident can freeze or clutter your notebook or terminal.
Resetting to the default
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:
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.
Related display options
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:
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:
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:
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.
Related reading
- Pandas sum DataFrame rows for given columns
- pandas three-way joining multiple dataframes on columns
- pandas unique values multiple columns
- pandas.factorize on an entire data frame
- pandas.parser.CParserError Error tokenizing data
- Parallel Import a python file from sibling folder
- Parallel processes in distributed tensorflow
- Parsing one terabyte of text and efficiently counting the number of occurrences of each word
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.