Pandas选项和自定义
Pandas提供API来自定义其行为的某些方面,大多使用来显示。
API由五个相关函数组成。它们分别是 -
- get_option()
- set_option()
- reset_option()
- describe_option()
- option_context()
现在来了解函数是如何工作的。
get_option(param)
get_option(param)
需要一个参数,并返回下面输出中给出的值 -
get_option
需要一个参数,并返回下面输出中给出的值 -
display.max_rows
显示默认值。解释器读取此值并显示此值作为显示上限的行。
import pandas as pd
print ("display.max_rows = ", pd.get_option("display.max_rows"))
执行上面示例代码,得到以下结果 -
display.max_rows = 60
display.max_columns
显示默认值,解释器读取此值并显示此值作为显示上限的行。
import pandas as pd
print ("display.max_columns = ", pd.get_option("display.max_columns"))
执行上面示例代码,得到以下结果 -
display.max_columns = 20
这里,60
和20
是默认配置参数值。
set_option(param,value)
set_option
需要两个参数,并将该值设置为指定的参数值,如下所示:
display.max_rows
使用set_option()
,可以更改要显示的默认行数。
import pandas as pd
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
display.max_columns
使用set_option()
,可以更改要显示的默认行数。
import pandas as pd
print ("before set display.max_columns = ", pd.get_option("display.max_columns"))
pd.set_option("display.max_columns",32)
print ("after set display.max_columns = ", pd.get_option("display.max_columns"))
执行上面示例代码,得到以下结果 -
before set display.max_columns = 20
after set display.max_columns = 32
reset_option(param)
reset_option
接受一个参数,并将该值设置为默认值。
display.max_rows
使用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
打印参数的描述。
display.max_rows
使用reset_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
上下文管理器用于临时设置语句中的选项。当退出使用块时,选项值将自动恢复 -
display.max_rows
使用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
10
请参阅第一和第二个打印语句之间的区别。第一个语句打印由option_context()
设置的值,该值在上下文中是临时的。在使用上下文之后,第二个打印语句打印配置的值。
常用参数,请参考下表 -
编号 | 参数 | 描述 |
---|---|---|
1 | display.max_rows |
要显示的最大行数 |
2 | display.max_columns |
要显示的最大列数 |
3 | display.expand_frame_repr |
显示数据帧以拉伸页面 |
4 | display.max_colwidth |
显示最大列宽 |
5 | display.precision |
显示十进制数的精度 |
Pandas选项和自定义的更多相关文章
- Pandas | 12 选项和自定义
Pandas提供API来自定义其行为的某些方面,大多使用来显示. API由五个相关函数组成.它们分别是: get_option() set_option() reset_option() descri ...
- Django(十八)后台管理:列表页选项、编辑页选项、自定义后台页面
[参考]https://blog.csdn.net/u010132177/article/details/103814357 [参考]https://docs.djangoproject.com/zh ...
- Pandas教程目录
Pandas数据结构 Pandas系列 Pandas数据帧(DataFrame) Pandas面板(Panel) Pandas基本功能 Pandas描述性统计 Pandas函数应用 Pandas重建索 ...
- Python人工智能学习笔记
Python教程 Python 教程 Python 简介 Python 环境搭建 Python 中文编码 Python 基础语法 Python 变量类型 Python 运算符 Python 条件语句 ...
- Font Combiner – 自定义网页字体和图标生成工具
Font Combiner 是一个功能丰富的 Web 字体生成工具和字体改进工具,提供字距调整.构造子集.各种提示选项和自定义字体字形组合.您可以生成您自己的自定义字体的格式和文件大小. 另外还有成千 ...
- 【大盛】HTC one/M7 ROM 最新本地化OrDroid8.2.6 高级、快速设置 永久root 更多自定义 稳定 流畅
了解更多:点击下载ROM和学习更多 ROM版本 HTC-one_OrDroid8.2.6 ROM作者 雪狼团队·大盛 http://weibo.com/DaShengdd Android版本 Andr ...
- 自定义和扩展 SharePoint 2010 Server 功能区
了解构成 SharePoint 2010 服务器功能区的组件以及如何通过演练两个功能区自定义项方案来自定义功能区. 适用范围: Microsoft SharePoint Foundation 2010 ...
- HTC one/M7电信802d 毒蛇ViperOne2.1.0/高级毒蛇工具/完美root,精简/更多自定义,稳定,流畅ROM
ROM版本 HTC One/M7 802d ROM作者 雪狼团队·大盛 http://weibo.com/DaShengdd Android版本 Android 4.2.2 创建日期 2013.09. ...
- vs2012 网站无法使用自定义服务器的解决方法
我已经习惯新建一个Asp.net网站时把它挂载在IIS下调试运行,在使用Visual Studio 2012后,新建网站配置启动选项时,自定义服务器居然不可用 原来是Visual Studio 201 ...
随机推荐
- nodemailer发送邮件各个服务器接口
来自:https://github.com/nodemailer/nodemailer-wellknown/blob/master/services.json#L125 { "1und1 ...
- OracleUNDO
UNDO作用 数据的回滚 一致性读 表的闪回(事务,查询的闪回....) 失败会话的恢复 数据的回滚 SQL> rollback; 回滚的过程就是从回滚段里拿到刚刚执行的这条语句产生的回滚,然后 ...
- spring 攻略
1.5 指定Bean引用 为了Bean之间相互访问,在Bean配置文件中通过<ref>元素为Bean属性或构造程序参数指定Bean引用. <property name="p ...
- HTTP 常见状态码
1. 以"1"开头(临时响应) 100: Continue,请求者应当继续提出请求;表示服务端已经收到请求的一部分,正在等待其余部分; 101: Switching Protoco ...
- eclipse欺骗了我
Java源文件(.java)和Java的字节码文件(.class)跟 package 是个什么关系? 平时使用 eclipse 的时候,发现 .java 文件目录必须和 package 包名保持一致, ...
- 用python简便地抓取刘昊然的写真(17行代码)
17行python代码抓取刘昊然图片之家的写真 用python来爬取网页信息是很简便的.因为它有很多库来帮助我们实现我们想要的功能.本实验用到的库有:requests和bs4中的BeautifulSo ...
- java反射基础知识(五)反射应用实践
详解Java反射各种应用 Java除了给我们提供在编译期得到类的各种信息之外,还通过反射让我们可以在运行期间得到类的各种信息.通过反射获取类的信息,得到类的信息之后,就可以获取以下相关内容: Cl ...
- 如何在浏览器网页中显示word文件内容
如何在浏览器网页中显示word文件内容 把word文件读到byte[]中,再Response.OutputStream.Write(bytes)到客户端去 Page_Load事件中写: //FileS ...
- 基本数据类型(Day4)
一 什么是数据? eg:x=10 则10是要存储的数据 二 为什么数据要分不同的类型? 数据是用来表示不同状态的,当然不同的状态可以用不同的数据表示 三 数据类型 1.数字(整型,长整型 ,浮 ...
- 【转】Python爬虫(7)_scrapy-redis
scrapy-redis使用以及剖析 scrapy-redis是一个基于redis的scrapy组件,通过它可以快速实现简单分布式爬虫程序,该组件本质上提供了三大功能: scheduler - 调 ...