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. 2 datax mysql 和 mysql之间相互导入

    插件文档: https://github.com/alibaba/DataX/blob/master/hdfswriter/doc/hdfswriter.md   1,参照第1篇日记,安装好datax ...

  2. 一个简单的 ValueTask 的示例

    Task 确实有潜在的缺点,特别是对于实例创建很多  并且高吞吐量和性能是关键问题的场景  :  Task 是一个类.作为一个类,这意味着任何需要创建一个对象的操作都需要分配一个对象,分配的对象越多, ...

  3. 趣文:如何通过给MM修电脑培养感情[转]

    在修之前,向 MM 反复声明,这电脑故障是有硬件和软件之分的,如果是硬件故障,例如显卡风扇不转了,显示器连线老化,显示器分辨率超出显示器指标,等等都会导致黑屏啊,这个我不回家用专门的工具是修不好的! ...

  4. python网络爬虫(1)——安装scrapy框架的常见问题及其解决方法

    Scrapy是为了爬取网站数据而编写的一款应用框架,出名,强大.所谓的框架其实就是一个集成了相应的功能且具有很强通用性的项目模板. 其实在Linux和 Mac安装,就简单的pip命令即可: pip i ...

  5. CSS之flex布局和边框阴影

    flex布局 main axis:主轴:cross axis:交叉轴 容器的子元素自动成为容器成员,成为flex 项目(item) flex容器属性 flex-direction ​ 该属性决定主轴的 ...

  6. jquery validate 动态生成的多个同名input的验证

    我的应用场景是,添加和修改入库单的明细,明细是以表格的形式呈现,可以动态添加商品,用jquery.validate插件做数据验证. 由于jquery.validate插件验证同名的input时只验证第 ...

  7. thread stack size not set; configure via D:\Program Files\elasticsearch-5.0.0\config\jvm.options or ES_JAVA_OPTS

    抄自:http://blog.csdn.net/leo063/article/details/52994786 thread stack size not set; configure via D:\ ...

  8. 设计模式:单例(Sigleton)模式

    题目:设计一个类,我们只能生成该类的一个实例. 只能生成一个实例的类是实现了Singleton(单例)模式的类型. 相关知识: 这种模式涉及到一个单一的类,该类负责创建自己的对象,同时确保只有单个对象 ...

  9. Python Django Vue 项目创建

    环境安装忽略,可参考前面个篇幅介绍 1.创建项目 打开pycharm 终端,输入如下,创建项目 # 进入pycharm 项目目录下 cd pyWeb django-admin startproject ...

  10. 尚硅谷MySQL高级学习笔记

    目录 数据库MySQL学习笔记高级篇 写在前面 1. mysql的架构介绍 mysql简介 mysqlLinux版的安装 mysql配置文件 mysql逻辑架构介绍 mysql存储引擎 2. 索引优化 ...