Pandas提供API来自定义其行为的某些方面,大多使用来显示。

API由五个相关函数组成。它们分别是:

  • get_option()
  • set_option()
  • reset_option()
  • describe_option()
  • option_context()

常用参数,请参考下表:

编号 参数 描述
1 display.max_rows 要显示的最大行数
2 display.max_columns 要显示的最大列数
3 display.expand_frame_repr 显示数据帧以拉伸页面
4 display.max_colwidth 显示最大列宽
5 display.precision 显示十进制数的精度

get_option(param)

get_option(param)需要一个参数,并返回给出的值。

  • display.max_rows显示默认值。解释器读取此值并显示此值作为显示上限的行。
  • display.max_columns显示默认值,解释器读取此值并显示此值作为显示上限的行。
import pandas as pd

print ("display.max_rows = ", pd.get_option("display.max_rows"))
print ("display.max_columns = ", pd.get_option("display.max_columns"))

输出结果 -

display.max_rows = 60
display.max_columns = 20


这里,6020是默认配置参数值。

set_option(param,value)

set_option需要两个参数,并将该值设置为指定的参数值.

import pandas as pd

print ("before set display.max_rows = ", pd.get_option("display.max_rows"))
print ("before set display.max_columns = ", pd.get_option("display.max_columns")) pd.set_option("display.max_rows",80)
pd.set_option("display.max_columns",42)
print ("after set display.max_rows = ", pd.get_option("display.max_rows"))
print ("after set display.max_columns = ", pd.get_option("display.max_columns"))

输出结果:

before set display.max_rows = 60
before set display.max_columns = 20

after set display.max_rows = 80
after set display.max_columns = 42


 

reset_option(param)

reset_option接受一个参数,并将该值设置为默认值。

import pandas as pd

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)

describe_option打印参数的描述。

import pandas as pd

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]
 

option_context()

option_context上下文管理器用于临时设置语句中的选项。当退出使用块时,选项值将自动恢复.

import pandas as pd

with pd.option_context("display.max_rows",10):
print(pd.get_option("display.max_rows")) print(pd.get_option("display.max_rows"))
输出结果:
10
60
 

第一个语句打印由option_context()设置的值,该值在上下文中是临时的。在使用上下文之后,第二个打印语句打印配置的值。

Pandas | 12 选项和自定义的更多相关文章

  1. Pandas高级教程之:自定义选项

    目录 简介 常用选项 get/set 选项 经常使用的选项 最大展示行数 超出数据展示 最大列的宽度 显示精度 零转换的门槛 列头的对齐方向 简介 pandas有一个option系统可以控制panda ...

  2. Pandas选项和自定义

    Pandas提供API来自定义其行为的某些方面,大多使用来显示. API由五个相关函数组成.它们分别是 - get_option() set_option() reset_option() descr ...

  3. Django(十八)后台管理:列表页选项、编辑页选项、自定义后台页面

    [参考]https://blog.csdn.net/u010132177/article/details/103814357 [参考]https://docs.djangoproject.com/zh ...

  4. xmake从入门到精通12:通过自定义脚本实现更灵活地配置

    xmake是一个基于Lua的轻量级现代化c/c++的项目构建工具,主要特点是:语法简单易上手,提供更加可读的项目维护,实现跨平台行为一致的构建体验. 本文主要详细讲解下,如何通过添加自定义的脚本,在脚 ...

  5. asp.net core 系列 12 选项 TOptions

    一.概述 本章讲的选项模式是对Configuration配置的功能扩展. 讲这篇时有个专用名词叫“选项类(TOptions)” .该选项类作用是指:把选项类中的属性与配置来源中的键关联起来.举个例,假 ...

  6. 【python】pandas display选项

    import pandas as pd 1.pd.set_option('expand_frame_repr', False) True就是可以换行显示.设置成False的时候不允许换行 2.pd.s ...

  7. 《ArcGIS Runtime SDK for Android开发笔记》——(12)、自定义方式加载Bundle格式缓存数据

    随着ArcGIS 10.3的正式发布,Esri推出了新的紧凑型缓存格式以增强用户的访问体验.新的缓存格式下,Esri将缓存的索引信息.bundlx包含在了缓存的切片文件.bundle中.具体如下图所示 ...

  8. Ubuntu 12.04 中自定义DNS服务器设置

    首先我们需要创建一个文件/etc/resolvconf/resolv.conf.d/tail: #vim /etc/resolvconf/resolv.conf.d/tail 然后我们在这个文件里写入 ...

  9. AJ学IOS 之微博项目实战(12)发送微博自定义工具条代理实现点击事件

    AJ分享,必须精品 一:效果 二:封装好的工具条 NYComposeToolbar.h 带代理方法 #import <UIKit/UIKit.h> typedef enum { NYCom ...

随机推荐

  1. 高通msm8909打开debug串口

    1.修改板级文件 $ cd AOSP $ vim device/qcom/msm8909/BoardConfig.mk 如下所示: 2.修改defconfig文件 $ cd kernel/arch/a ...

  2. TCP连接的建立(三次握手和四次挥手)

    写到最后发现我描述的挺水的,这个老哥的用语比较专业一点https://blog.csdn.net/qq_38950316/article/details/81087809  (老哥这篇有些许错别字 大 ...

  3. VSCode打字特效Power Mode插件

    由于最近比较频繁使用VSCode这个软件写代码,然后里面有一个非常炫酷的打字特效插件,平时写代码的时候不会感觉太枯燥(其实就是装一下逼吧)! 安装很简单,但是容易忘,所以这里整理一下具体的部署步骤. ...

  4. spring 核心容器

    核心容器包括了:Beans.Core.Context.SpEL 1. core和beans模块提供了整个框架最基础的部分,包括了IoC(控制反转)和Dependency Injection(依赖注入) ...

  5. JS提交表单页面不跳转、JS下载、动态创建from

    JS下载 function downloadFile(id) {     var url =  "<%=request.getContextPath()%>/cer/downlo ...

  6. TCP的三次握手过程?为什么会采用三次握手,若采用二次握手可以吗

    谢希仁版<计算机网络>中的例子: "已失效的连接请求报文段”的产生在这样一种情况下: client发出的第一个连接请求报文段并没有丢失,而是在某个网络结点长时间的滞留了,以致延误 ...

  7. web api对接小程序基本签名认证

    using BMOA.Application.System; using BMOA.Common; using BMOA.Web.Models; using Newtonsoft.Json; usin ...

  8. python高级编程——网络编程(二)

    UDP 概念和介绍 UDP --- 用户数据报协议,是一个无连接的简单的面向数据报的运输层协议. UDP不提供可靠性,它只是把应用程序传给IP层的数据报发送出去,但是并 不能保证它们能到达目的地. U ...

  9. 如何设计提高服务API的安全性(一)基础介绍

    场景 现今越来越多公司提供了Sass平台服务,大部分也直接提供API.如快递鸟.微信Api.云服务.如何保证这些服务的安全性是一门重要的课题.如快递跟踪.机票查询等很便捷地影响着我们d的生活,对这些技 ...

  10. APP手势密码绕过

    之前写的文章收到了很多的好评,主要就是帮助到了大家学习到了新的思路.自从发布了第一篇文章,我就开始筹备第二篇文章了,最终打算在07v8首发,这篇文章我可以保障大家能够学习到很多思路.之前想准备例子视频 ...