Python中的Pandas.get_option()函数
Pandas有一个选项系统,可以让你定制其行为的某些方面,与显示有关的选项是用户最可能调整的。让我们看看如何看到一个指定选项的值。
get_option()
语法 :
pandas.get_option(pat)
参数 :
- pat :应该匹配单个选项的Regexp。
如果不存在这样的选项,会引发: OptionError
示例1 :获取可显示的最大和最小列数和行数的值。
# importing the module
import pandas as pd
# fetching maximum number of
# columns that can be displayed
print("The value of max_columns : " +
str(pd.get_option("display.max_columns")))
# fetching maximum number of
# rows that can be displayed
print("The value of max_rows : " +
str(pd.get_option("display.max_rows")))
# fetching minimum number of
# rows that can be displayed
print("The value of min_rows : " +
str(pd.get_option("display.min_rows")))
输出 :
输出可能有所不同。
例子2:获取与Excel文件有关的属性。
# importing the module
import pandas as pd
# default Excel reader engine for ‘ods’ files
print("The default Excel reader engine for ‘ods’ files : " +
str(pd.get_option("io.excel.ods.reader")))
# default Excel reader engine for ‘xls’ files
print("The default Excel reader engine for ‘xls’ files : " +
str(pd.get_option("io.excel.xls.reader")))
# default Excel writer engine for ‘xls’ files
print("The default Excel writer engine for ‘xls’ files : " +
str(pd.get_option("io.excel.xls.writer")))
# default Excel reader engine for ‘xlsb’ files
print("The default Excel reader engine for ‘xlsb’ files : " +
str(pd.get_option("io.excel.xlsb.reader")))
# default Excel reader engine for ‘xlsm’ files
print("The default Excel reader engine for ‘xlsm’ files : " +
str(pd.get_option("io.excel.xlsm.reader")))
# default Excel writer engine for ‘xlsm’ files
print("The default Excel writer engine for ‘xlsm’ files : " +
str(pd.get_option("io.excel.xlsm.writer")))
# default Excel reader engine for ‘xlsm’ files
print("The default Excel reader engine for ‘xlsx’ files : " +
str(pd.get_option("io.excel.xlsx.reader")))
# default Excel writer engine for ‘xlsx’ files
print("The default Excel writer engine for ‘xlsx’ files : " +
str(pd.get_option("io.excel.xlsx.writer")))
输出 :