Pandas | 12 选项和自定义
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
这里,60
和20
是默认配置参数值。
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 选项和自定义的更多相关文章
- Pandas高级教程之:自定义选项
目录 简介 常用选项 get/set 选项 经常使用的选项 最大展示行数 超出数据展示 最大列的宽度 显示精度 零转换的门槛 列头的对齐方向 简介 pandas有一个option系统可以控制panda ...
- Pandas选项和自定义
Pandas提供API来自定义其行为的某些方面,大多使用来显示. API由五个相关函数组成.它们分别是 - get_option() set_option() reset_option() descr ...
- Django(十八)后台管理:列表页选项、编辑页选项、自定义后台页面
[参考]https://blog.csdn.net/u010132177/article/details/103814357 [参考]https://docs.djangoproject.com/zh ...
- xmake从入门到精通12:通过自定义脚本实现更灵活地配置
xmake是一个基于Lua的轻量级现代化c/c++的项目构建工具,主要特点是:语法简单易上手,提供更加可读的项目维护,实现跨平台行为一致的构建体验. 本文主要详细讲解下,如何通过添加自定义的脚本,在脚 ...
- asp.net core 系列 12 选项 TOptions
一.概述 本章讲的选项模式是对Configuration配置的功能扩展. 讲这篇时有个专用名词叫“选项类(TOptions)” .该选项类作用是指:把选项类中的属性与配置来源中的键关联起来.举个例,假 ...
- 【python】pandas display选项
import pandas as pd 1.pd.set_option('expand_frame_repr', False) True就是可以换行显示.设置成False的时候不允许换行 2.pd.s ...
- 《ArcGIS Runtime SDK for Android开发笔记》——(12)、自定义方式加载Bundle格式缓存数据
随着ArcGIS 10.3的正式发布,Esri推出了新的紧凑型缓存格式以增强用户的访问体验.新的缓存格式下,Esri将缓存的索引信息.bundlx包含在了缓存的切片文件.bundle中.具体如下图所示 ...
- Ubuntu 12.04 中自定义DNS服务器设置
首先我们需要创建一个文件/etc/resolvconf/resolv.conf.d/tail: #vim /etc/resolvconf/resolv.conf.d/tail 然后我们在这个文件里写入 ...
- AJ学IOS 之微博项目实战(12)发送微博自定义工具条代理实现点击事件
AJ分享,必须精品 一:效果 二:封装好的工具条 NYComposeToolbar.h 带代理方法 #import <UIKit/UIKit.h> typedef enum { NYCom ...
随机推荐
- python 多线程剖析
先来看个栗子: 下面来看一下I/O秘籍型的线程,举个栗子——爬虫,下面是爬下来的图片用4个线程去写文件 #!/usr/bin/env python # -*- coding:utf-8 -*- imp ...
- Swagger 自定义UI界面
Swagger 自定义UI界面 Swagger简单介绍 如何使用Swagger 添加自定义UI界面 使用swagger-ui-layer Swagger ui 的原生UI界面如下: 个人感觉原生UI显 ...
- 【模板整合计划】NB数论
[模板整合计划]NB数论 一:[质数] 1.[暴力判] 素数.コンテスト.素数 \(\text{[AT807]}\) #include<cstdio> #include<cmath& ...
- 使用Redis实现中英文自动补全功能详解
1.Redis自动补全功能介绍: Redis可以帮我们实现很多种功能,今天这里着重介绍的是Redis的自动补全功能的实现.我们使用有序集合,并score都为0,这样就按元素值的字典序排序.然后我们 ...
- GAN——生成手写数字
<Generative Adversarial Nets>是 GAN 系列的鼻祖.在这里通过 PyTorch 实现 GAN ,并且用于手写数字生成. 摘要: 我们提出了一个新的框架,通过对 ...
- 2019-11-29-WPF-如何在绑定失败异常
原文:2019-11-29-WPF-如何在绑定失败异常 title author date CreateTime categories WPF 如何在绑定失败异常 lindexi 2019-11-29 ...
- MySQL 8.0.13安装修改密码的一个问题,记录一下。
https://blog.csdn.net/qq_37350706/article/details/81707862 关于安装MySQL 8.0.13,本人就不多说了,上面这个链接讲的非常详细 请参考 ...
- 记录RFID操作错误
如果代码操作不了RFID设备,查看下通信协议的设置
- JavaScript学习思维导图
JS基本概念 JS操作符 JS基本语法 JS数组 JS Date用法 JS 字符串用法 JS编程风格 JS实践
- 消息队列mq总结
一.消息队列概述消息队列中间件是分布式系统中重要的组件,主要解决应用解耦,异步消息,流量削锋等问题,实现高性能,高可用,可伸缩和最终一致性架构.目前使用较多的消息队列有ActiveMQ,RabbitM ...