Pandas Display Options: Inspect, Format and Restore

Choose Pandas display settings, inspect defaults, format previews and restore previous options without changing table data.

Choose a display task 🔝

Pandas options control rendering and other session behaviour; there is no DataFrame.display method. Display settings do not change table values. Use the detailed tutorials below for each operation.

Create a small synthetic report 🔝

Use a repeatable embedded table rather than a local workbook. All values are synthetic practice data.
import pandas as pd
report = pd.DataFrame({"record": range(1, 13), "amount": [i / 3 for i in range(1, 13)],
    "region": ["North", "South"] * 6, "status": ["paid"] * 12})
print(report.head(3))
assert report.shape == (12, 4)

Expected output

   record    amount region status
0       1  0.333333  North   paid
1       2  0.666667  South   paid
2       3  1.000000  North   paid

Set multiple display options 🔝

Retain the original max_rows=100 and max_columns=50 example. These changes affect session-wide rendering until restored. try/finally keeps this demonstration from leaving persistent settings behind.
saved_rows = pd.get_option("display.max_rows")
saved_columns = pd.get_option("display.max_columns")
try:
    pd.set_option("display.max_rows", 100, "display.max_columns", 50)
    print("Row limit:", pd.get_option("display.max_rows"))
    print("Column limit:", pd.get_option("display.max_columns"))
    assert pd.get_option("display.max_rows") == 100
finally:
    pd.set_option("display.max_rows", saved_rows, "display.max_columns", saved_columns)
assert pd.get_option("display.max_rows") == saved_rows

Expected output

Row limit: 100
Column limit: 50

Render a temporary preview 🔝

For one inspection task, scope the options with a context. Explicit row/column limits and precision make the text preview repeatable; notebook HTML may render differently.
before = pd.get_option("display.precision")
with pd.option_context("display.max_rows", 6, "display.min_rows", 6,
                       "display.max_columns", 3, "display.precision", 2,
                       "display.width", 80, "display.show_dimensions", True):
    print(report)
assert pd.get_option("display.precision") == before
assert report.shape == (12, 4)

Expected output

    record  ...  status
0        1  ...    paid
1        2  ...    paid
2        3  ...    paid
..     ...  ...     ...
9       10  ...    paid
10      11  ...    paid
11      12  ...    paid

[12 rows x 4 columns]

Inspect the installed option description 🔝

Descriptions show registered defaults and current values. A current value can differ from the default. Use full option names rather than ambiguous partial matches.
pd.describe_option("display.precision")
print("Current precision:", pd.get_option("display.precision"))

Expected output

display.precision : int
    Floating point output precision in terms of number of places after the
    decimal, for regular formatting as well as scientific notation. Similar
    to ``precision`` in :meth:`numpy.set_printoptions`.
    [default: 6] [currently: 6]
Current precision: 6

Reset selected defaults 🔝

Retain the reset concept while targeting only the intended display options. reset_option("all") affects every registered setting and can invoke optional-library callbacks; it is not simply a display reset. Use the detailed reset tutorial for broad-reset guidance.
with pd.option_context("display.max_rows", 6, "display.max_columns", 3):
    pd.reset_option("display.max_rows")
    pd.reset_option("display.max_columns")
    print("Default row limit:", pd.get_option("display.max_rows"))
    print("Default column limit:", pd.get_option("display.max_columns"))
assert pd.get_option("display.max_rows") == saved_rows
assert pd.get_option("display.max_columns") == saved_columns

Expected output

Default row limit: 60
Default column limit: 0

Format output without changing stored numbers 🔝

to_string(index=False) hides labels in the text, not in the DataFrame. float_format controls this representation; it does not round the stored numeric values.
text = report.head(3).to_string(index=False, float_format=lambda value: f"{value:.2f}")
print(text)
assert report.loc[0, "amount"] == 1 / 3
assert len(report) == 12

Expected output

 record  amount region status
      1    0.33  North   paid
      2    0.67  South   paid
      3    1.00  North   paid

Display and data are different 🔝

Truncation hides some values in the representation; it does not filter records. Unlimited display can create excessive output. Precision affects presentation, not calculation. Text width and terminal auto-detection differ from notebook HTML. Options are shared session state; avoid overlapping changes in concurrent work. File exports such as to_csv() have their own formatting controls. For analysis continue to Data Analysis.

Exercise: show a two-row report 🔝

Print two rows with no index and three decimal places, without altering the underlying numeric values or the session precision setting.

Exercise solution 🔝

Use explicit output formatting for a single representation.
precision_before = pd.get_option("display.precision")
print(report.head(2).to_string(index=False, float_format=lambda value: f"{value:.3f}"))
assert pd.get_option("display.precision") == precision_before
assert report.loc[0, "amount"] == 1 / 3

Expected output

 record  amount region status
      1   0.333  North   paid
      2   0.667  South   paid

Practice in Google Colab 🔝

Open in Google Colab View on GitHub

Run examples in order, inspect the table display and try the exercise. Save a copy to keep edits.

Reference: Pandas Display Options documentation.




Subscribe to our YouTube Channel here



plus2net.com







Python Video Tutorials
Python SQLite Video Tutorials
Python MySQL Video Tutorials
Python Tkinter Video Tutorials
✖
We use cookies to improve your browsing experience. . Learn more
HTML MySQL PHP JavaScript ASP Photoshop Articles Contact us
© 2000-2026 plus2net.com All rights reserved worldwide Privacy Policy Disclaimer