Функция Pandas.reset_option () в Python
У Pandas есть система параметров, которая позволяет нам настраивать некоторые аспекты его поведения, причем параметры, связанные с отображением, - это те, которые пользователь, скорее всего, настроит. Давайте посмотрим, как сбросить значение указанной опции до значения по умолчанию.
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 of an option using pandas.get_option(), we will then reset it back to its default value using pandas.reset_option().
# importing the moduleimport pandas as pd # setting the valuespd.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 valuesprint("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 defaultpd.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 valuesprint("
The 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.
# importing the moduleimport pandas as pd # setting the valuespd.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 valuesprint("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 defaultpd.reset_option("all") # displaying the default valuesprint("
The 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 :
Attention geek! Strengthen your foundations with the Python Programming Foundation Course and learn the basics.
To begin with, your interview preparations Enhance your Data Structures concepts with the Python DS Course. And to begin with your Machine Learning Journey, join the Machine Learning – Basic Level Course