less than 1 minute read

If you want to temporarily change pandas options, instead of doing so manually as follows:

max_columns = pd.get_option('display.max_columns')
max_rows = pd.get_option('display.max_rows')

pd.set_option('display.max_columns', None)
pd.set_option('display.max_rows', None)
print(df)

pd.set_option('display.max_columns', max_columns)
pd.set_option('display.max_rows', max_rows)

you can use the option_context function to do so via a context:

with pd.option_context('display.max_rows', None, 'display.max_columns', None, ):
    print(df)

This will automatically return the options to their default values after printing the dataframe.

Via SO.

Leave a comment