Pandas-12.选项和设置选项
相关函数
Pandas有五个自定义其行为的函数:
- get_option(param) 获取当前解释器参数
print ("display.max_rows = ", pd.get_option("display.max_rows"))
# display.max_rows = 60 - 显示上限的行
print ("display.max_rows = ", pd.get_option("display.max_columns"))
# display.max_rows = 20 - 显示上限的列
- set_option(params, value) 将解释器的参数设定为指定值
print ("before set display.max_rows = ", pd.get_option("display.max_rows"))
pd.set_option("display.max_rows",80)
print ("after set display.max_rows = ", pd.get_option("display.max_rows"))
# before set display.max_rows = 60
# after set display.max_rows = 80
- reset_option(param) 将解释器的参数重置为默认值
pd.set_option("display.max_rows",32)
print ("after set display.max_rows = ", pd.get_option("display.max_rows"))
pd.reset_option("display.max_rows")
print ("reset display.max_rows = ", pd.get_option("display.max_rows"))
# after set display.max_rows = 32
# reset display.max_rows = 60
- describe_option(param) 打印参数的描述
pd.describe_option("display.max_rows")
'''
display.max_rows : int
If max_rows is exceeded, switch to truncate view. Depending on
`large_repr`, objects are either centrally truncated or printed as
a summary view. 'None' value means unlimited.
In case python/IPython is running in a terminal and `large_repr`
equals 'truncate' this can be set to 0 and pandas will auto-detect
the height of the terminal and print a truncated object which fits
the screen height. The IPython notebook, IPython qtconsole, or
IDLE do not run in a terminal and hence it is not possible to do
correct auto-detection.
[default: 60] [currently: 60]
'''
- options_context() 临时设置语句中的选项,退出使用块时,自动恢复选项
with pd.option_context("display.max_rows",10):
print(pd.get_option("display.max_rows"))
print(pd.get_option("display.max_rows"))
# 10
# 60
常用选项
参数 | 描述 |
---|---|
display.max_rows | 显示的最大行数 |
display.max_columns | 显示的最大列数 |
display.expend_frame_repr | 显示数据帧以拉伸页面 |
display.max_colwidth | 显示最大列宽 |
display.precision | 显示十进制数的精度 |