Open In App

Pandas.reset_option() function in Python

Last Updated : 28 Jun, 2022
Improve
Improve
Like Article
Like
Save
Share
Report

Pandas have an options system that lets us customize some aspects of its behavior, display-related options being those the user is most likely to adjust. Let us see how to reset the value of a specified option back to its default value.

reset_option()

Syntax : pandas.reset_option(pat) 

Parameters : 

  • pat : Regexp which should match a single option.

Returns : None

Example 1 : We will change the value of an option using pandas.get_option(), we will then reset it back to its default value using pandas.reset_option(). 

Python3




# importing the module
import pandas as pd
 
# setting the values
pd.set_option("display.max_rows", 10)
pd.set_option("display.min_rows", 2)
pd.set_option("display.max_columns", 5)
pd.set_option("display.html.border", 3)
pd.set_option("io.excel.xlsm.reader", "openpyxl")
 
# displaying the values
print("The altered values are : ")
print("Value of max_rows : " +
      str(pd.get_option("display.max_rows")))
 
print("Value of min_rows : " +
      str(pd.get_option("display.max_columns")))
 
print("Value of max_columns : " +
      str(pd.get_option("display.max_columns")))
 
print("Value of border : " +
      str(pd.get_option("display.html.border")))
 
print("Value of xlsm reader : " +
      str(pd.get_option("io.excel.xlsm.reader")))
 
# resetting the values to default
pd.reset_option("display.max_rows")
pd.reset_option("display.min_rows")
pd.reset_option("display.max_columns")
pd.reset_option("display.html.border")
pd.reset_option("io.excel.xlsm.reader")
 
# displaying the default values
print("\nThe default values are : ")
 
print("Value of max_rows : " +
      str(pd.get_option("display.max_rows")))
 
print("Value of min_rows : " +
      str(pd.get_option("display.max_columns")))
 
print("Value of max_columns : " +
      str(pd.get_option("display.max_columns")))
 
print("Value of border : " +
      str(pd.get_option("display.html.border")))
 
print("Value of xlsm reader : " +
      str(pd.get_option("io.excel.xlsm.reader")))


Output :

  

Example 2 : Instead of individually resetting the values of different options, we can reset the values of all the options at once by passing “all” as the parameter in the pandas.reset_option() function. 

Python3




# importing the module
import pandas as pd
 
# setting the values
pd.set_option("display.max_rows", 10)
pd.set_option("display.min_rows", 2)
pd.set_option("display.max_columns", 5)
pd.set_option("display.html.border", 3)
pd.set_option("io.excel.xlsm.reader", "openpyxl")
 
# displaying the values
print("The altered values are : ")
 
print("Value of max_rows : " +
      str(pd.get_option("display.max_rows")))
 
print("Value of min_rows : " +
      str(pd.get_option("display.max_columns")))
 
print("Value of max_columns : " +
      str(pd.get_option("display.max_columns")))
 
print("Value of border : " +
      str(pd.get_option("display.html.border")))
 
print("Value of xlsm reader : " +
      str(pd.get_option("io.excel.xlsm.reader")))
 
# resetting the values to default
pd.reset_option("all")
 
# displaying the default values
print("\nThe default values are : ")
 
print("Value of max_rows : " +
      str(pd.get_option("display.max_rows")))
 
print("Value of min_rows : " +
      str(pd.get_option("display.max_columns")))
 
print("Value of max_columns : " +
      str(pd.get_option("display.max_columns")))
 
print("Value of border : " +
      str(pd.get_option("display.html.border")))
 
print("Value of xlsm reader : " +
      str(pd.get_option("io.excel.xlsm.reader")))


Output :

 



Like Article
Suggest improvement
Previous
Next
Share your thoughts in the comments

Similar Reads