pandas.option_context#

pandas.option_context(*args)[source]#

Context manager to temporarily set options in a with statement.

This method allows users to set one or more pandas options temporarily within a controlled block. The previous options’ values are restored once the block is exited. This is useful when making temporary adjustments to pandas’ behavior without affecting the global state.

Parameters:
*argsstr | object

An even amount of arguments provided in pairs which will be interpreted as (pattern, value) pairs.

Returns:
None

No return value.

Yields:
None

No yield value.

See also

get_option

Retrieve the value of the specified option.

set_option

Set the value of the specified option.

reset_option

Reset one or more options to their default value.

describe_option

Print the description for one or more registered options.

Notes

For all available options, please view the User Guide or use pandas.describe_option().

Examples

>>> from pandas import option_context
>>> with option_context("display.max_rows", 10, "display.max_columns", 5):
...     pass