Inspect registered Pandas option descriptions, distinguish default and current values and generate the installed option catalogue.
Show Table of Contents ↓import pandas as pd
pd.describe_option("display.max_rows")
assert isinstance(pd.get_option("display.max_rows"), (int, type(None)))Expected output
display.max_rows : int
If max_rows is exceeded, switch to truncate view. Depending on
`large_repr`, objects are either centrally truncated or printed as
a summary view.
'None' value means unlimited. Beware that printing a large number of rows
could cause your rendering environment (the browser, etc.) to crash.
In case python/IPython is running in a terminal and `large_repr`
equals 'truncate' this can be set to 0 and pandas will auto-detect
the height of the terminal and print a truncated object which fits
the screen height. The IPython notebook, IPython qtconsole, or
IDLE do not run in a terminal and hence it is not possible to do
correct auto-detection.
[default: 60] [currently: 60]before = pd.get_option("display.max_rows")
with pd.option_context("display.max_rows", 10):
pd.describe_option("display.max_rows")
assert pd.get_option("display.max_rows") == 10
print("Previous value restored:", pd.get_option("display.max_rows") == before)
assert pd.get_option("display.max_rows") == beforeExpected output
display.max_rows : int
If max_rows is exceeded, switch to truncate view. Depending on
`large_repr`, objects are either centrally truncated or printed as
a summary view.
'None' value means unlimited. Beware that printing a large number of rows
could cause your rendering environment (the browser, etc.) to crash.
In case python/IPython is running in a terminal and `large_repr`
equals 'truncate' this can be set to 0 and pandas will auto-detect
the height of the terminal and print a truncated object which fits
the screen height. The IPython notebook, IPython qtconsole, or
IDLE do not run in a terminal and hence it is not possible to do
correct auto-detection.
[default: 60] [currently: 10]
Previous value restored: Truepd.describe_option(r"^display\.max_(rows|columns)$")Expected output
display.max_columns : int
If max_cols is exceeded, switch to truncate view. Depending on
`large_repr`, objects are either centrally truncated or printed as
a summary view.
'None' value means unlimited. Beware that printing a large number of
columns could cause your rendering environment (the browser, etc.) to
crash.
In case python/IPython is running in a terminal and `large_repr`
equals 'truncate' this can be set to 0 or None and pandas will auto-detect
the width of the terminal and print a truncated object which fits
the screen width. The IPython notebook, IPython qtconsole, or IDLE
do not run in a terminal and hence it is not possible to do
correct auto-detection and defaults to 20.
[default: 0] [currently: 0]
display.max_rows : int
If max_rows is exceeded, switch to truncate view. Depending on
`large_repr`, objects are either centrally truncated or printed as
a summary view.
'None' value means unlimited. Beware that printing a large number of rows
could cause your rendering environment (the browser, etc.) to crash.
In case python/IPython is running in a terminal and `large_repr`
equals 'truncate' this can be set to 0 and pandas will auto-detect
the height of the terminal and print a truncated object which fits
the screen height. The IPython notebook, IPython qtconsole, or
IDLE do not run in a terminal and hence it is not possible to do
correct auto-detection.
[default: 60] [currently: 60]import io
from contextlib import redirect_stdout
buffer = io.StringIO()
with redirect_stdout(buffer):
pd.describe_option()
catalogue = buffer.getvalue()
headers = [line.split(" :", 1)[0] for line in catalogue.splitlines()
if line and not line[0].isspace() and " :" in line]
for prefix in ["display.", "compute.", "io.", "mode.", "plotting."]:
print(prefix, sum(name.startswith(prefix) for name in headers))
assert "display.max_rows" in catalogue and "display.max_columns" in catalogueExpected output
display. 29
compute. 3
io. 12
mode. 5
plotting. 2| Group | Purpose |
|---|---|
| display | Text/HTML rendering, rows, columns, width, precision and related presentation. |
| compute | Computation-related settings; available acceleration depends on installed libraries. |
| io | File reader/writer configuration and engines. |
| mode | Behaviour settings; some historical options are deprecated or removed. |
| plotting | Plot backends and related configuration. |
The no-argument catalogue includes all registered options, not just display options. Describing an option does not install its optional dependency or change its value. Do not copy removed historical option names such as display.column_space or mode.use_inf_as_null into current code.
pd.describe_option("display.precision")
data = pd.DataFrame({"amount": [1.23456, 9.87654]})
with pd.option_context("display.precision", 2):
print(data)
assert data["amount"].tolist() == [1.23456, 9.87654]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]
amount
0 1.23
1 9.88saved = pd.get_option("display.precision")
pd.describe_option("display.precision")
with pd.option_context("display.precision", 3):
print("Inside:", pd.get_option("display.precision"))
assert pd.get_option("display.precision") == 3
print("Restored:", pd.get_option("display.precision") == saved)
assert pd.get_option("display.precision") == savedExpected 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]
Inside: 3
Restored: TrueOpen 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 describe_option() documentation.
Author & Instructor at plus2net
I write and maintain practical tutorials on Python, PHP, SQL, JavaScript, HTML, jQuery, and web development at plus2net. The tutorials focus on clear explanations, working examples, and code that readers can test and adapt while learning.