Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Restoring the default display context in Pandas

Tags:

python

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), ...)).
like image 372
Amelio Vazquez-Reina Avatar asked Oct 07 '14 23:10

Amelio Vazquez-Reina


People also ask

How do I reset my PD options?

Use pandas. reset_option("all") to reset all display options.

What is PD Set_option in Python?

set_option(param,value) Using set_option(), we can change the default number of rows to be displayed. import pandas as pd pd. set_option("display.max_rows",80) print pd. get_option("display.max_rows") Its output is as follows − 80.

How do you undo operation in pandas?

CTRL + Z is the only thing that I can think of.

How do I get pandas to show all rows?

Set value of display. max_rows to None and pass it to set_option and this will display all rows from the data frame.


1 Answers

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)
like image 156
elyase Avatar answered Oct 20 '22 19:10

elyase