首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >Pandas-12.选项和设置选项

Pandas-12.选项和设置选项

作者头像
悠扬前奏
发布2019-05-29 17:16:43
1.2K0
发布2019-05-29 17:16:43
举报

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

显示十进制数的精度

本文参与 腾讯云自媒体分享计划,分享自作者个人站点/博客。
原始发表:2019.04.03 ,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体分享计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • Pandas-12.选项和设置选项
    • 相关函数
      • 常用选项
      领券
      问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档