Wrap your print() statement inside with pd.option_context("display.max_rows", None, "display.max_columns", None, "display.width", None, "display.max_colwidth", None): for a temporary, zero-side-effect full printout—or call print(df.to_string()) / print(s.to_string()) directly when you want every row, column, and full cell value printed in a single call without modifying global Pandas settings.
Basic Example
import pandas as pd
df = pd.DataFrame({
f"col_{c}": [f"row_{r}_value_with_long_text" for r in range(100)]
for c in range(20)
})
s = pd.Series([f"item_{i}_extended_description" for i in range(100)])
# 1. Recommended for one-off inspection: Temporary option_context (auto-resets after block)
with pd.option_context(
"display.max_rows", None,
"display.max_columns", None,
"display.width", None,
"display.max_colwidth", None,
):
print(df)
print(s)
# 2. Concise single-expression alternative (prints every row, column, and full cell text)
print(df.to_string())
print(s.to_string())
# 3. Set globally for an entire script or Jupyter notebook session
pd.set_option("display.max_rows", None)
pd.set_option("display.max_columns", None)
pd.set_option("display.width", None)
pd.set_option("display.max_colwidth", None)
Key Details & Edge Cases
- Why all four display options are needed for truly untruncated output:
display.max_rows = None: Prevents DataFrames or Series with more than 60 rows from collapsing middle rows into.display.max_columns = None: Prevents wide DataFrames from hiding middle columns with(ignored bySeries, which has one column).display.width = None: Prevents terminal scripts (python script.py) from wrapping wide DataFrames into stacked vertical blocks with\continuation characters at 80 characters.display.max_colwidth = None: Prevents long strings inside individual cells (over 50 characters) from being cut off with.
- Series-specific
display.max_seq_itemsdetail:- While
display.max_rows = Nonecontrolspd.Seriesprinting, printing rawdf.indexordf.columnsobjects separately is governed bydisplay.max_seq_items(default100). Set"display.max_seq_items", Noneif you also print hugeIndexobjects without.
- While
- Performance and memory warning on huge DataFrames (> 10,000 rows):
- Calling
df.to_string()or settingdisplay.max_rows = Noneon a 500,000-row DataFrame formats every cell into one massive string in RAM—which can take several seconds and freeze a Jupyter notebook browser tab or flood your terminal scrollback buffer. - For large datasets, prefer inspecting targeted slices (
print(df.head(200).to_string())) or writing to a temporary text/CSV file (df.to_csv("debug_dump.csv")) to view in an editor.
- Calling
- Jupyter Notebook HTML vs. plain-text
print():- Evaluating
dfas the last expression in a Jupyter cell renders an HTML table that obeysdisplay.max_rows,display.max_columns, anddisplay.max_colwidth(while scrolling horizontally natively in CSS). Usingprint(df)inside Jupyter falls back to plain-text formatting, which does requiredisplay.width = Noneto avoid line wrapping.
- Evaluating
Comparison of Untruncated Pandas Printing Approaches
| Method | Syntax | Affects Global Settings? | Works on Both DataFrame & Series? | Best Used When |
|---|---|---|---|---|
pd.option_context(...) |
with pd.option_context("display.max_rows", None, ...): print(df) |
No (auto-restores on exit) | Yes | Temporary full inspection inside scripts or functions without side effects. |
.to_string() |
print(df.to_string()) / print(s.to_string()) |
No | Yes | Quick one-line full printout of small-to-medium DataFrames or Series. |
pd.set_option(...) |
pd.set_option("display.max_rows", None) (etc.) |
Yes (session-wide) | Yes | Configuring a Jupyter notebook or exploratory script at the top of the file. |
pd.reset_option(...) |
pd.reset_optio("regex_pattern") |
Yes (reverts to default) | Yes | Restoring default Pandas truncation limits after global overrides. |
You must log in or register to comment.
