Amelio Vazquez-Reina
Amelio Vazquez-Reina

Reputation: 96360

Restoring the default display context in Pandas

I have found myself in cases where I accidentally run:

pd.option_context('display.max_columns', None, 
                  'display.max_rows', None, 
                  'display.width', None, 
                  'display.max_colwidth', 0)

without the with clause. Unfortunately, that changes my default printing options for all my print statements.

My question is: How can I restore the default context?

Calling pd.option_context() without arguments doesn't work, I get:

ValueError: Need to invoke asoption_context(pat, val, [(pat, val), ...)).

Upvotes: 15

Views: 23160

Answers (3)

Julia Zhao
Julia Zhao

Reputation: 909

pd.reset_option('display.max_columns', 0) restores the display of columns to the default setting. Other options can be reset in a similar manner.

Upvotes: 0

Joop
Joop

Reputation: 3788

Use reset_option('all') to reset all options.

Credits: answer taken from the comment of @joris. I am posting this as the search-engine guided me here when I searched for how to reset all options, and comments are easy to miss.

Upvotes: 4

elyase
elyase

Reputation: 40973

You can use pd.reset_option to reset one option or you can use a regex to reset more than one at the same time. In your case to reset all options starting with display you can do:

pd.reset_option('^display.', silent=True)

Upvotes: 29

Related Questions