📜  Python中的 Pandas.get_option()函数

📅  最后修改于: 2022-05-13 01:55:45.981000             🧑  作者: Mango

Python中的 Pandas.get_option()函数

Pandas 有一个选项系统,可让您自定义其行为的某些方面,与显示相关的选项是用户最有可能调整的选项。让我们看看如何查看指定选项的值。

获取选项()

示例 1:获取可以显示的最大和最小列数和行数的值。

Python3
# 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")))


Python3
# 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")))


输出 :

输出可能会有所不同。

示例 2:获取与 Excel 文件相关的属性。

Python3

# 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")))

输出 :