浅谈pandas中DataFrame关于显示值省略的解决方法


Posted in Python onApril 08, 2018

python的pandas库是一个非常好的工具,里面的DataFrame更是常用且好用,最近是越用越觉得设计的漂亮,pandas的很多细节设计的都非常好,有待使用过程中发掘。

好了,发完感慨,说一下最近DataFrame遇到的一个细节:

在使用DataFrame中有时候会遇到表格中的value显示不完全,像下面这样:

In:
import pandas as pd
longString = u'''真正的科学家应当是个幻想家;谁不是幻想家,谁就只能把自己称为实践家。人生的磨难是很多的,
所以我们不可对于每一件轻微的伤害都过于敏感。在生活磨难面前,精神上的坚强和无动于衷是我们抵抗罪恶和人生意外的最好武器。'''
pd.DataFrame({'word':[longString]})

输出如下:

浅谈pandas中DataFrame关于显示值省略的解决方法

可以看到,显示值长度为50个后就出现了省略了,这个因为DataFrame默认的显示长度为50,不过可以改默认设置:

pd.set_option('max_colwidth',200)
pd.DataFrame({'word':[longString]})

浅谈pandas中DataFrame关于显示值省略的解决方法

通过设置就可以改变显示长度了。

关于set_option所有的参数介绍如下:

Available options:
- display.[chop_threshold, colheader_justify, column_space, date_dayfirst,
 date_yearfirst, encoding, expand_frame_repr, float_format, height, large_repr]
- display.latex.[escape, longtable, repr]
- display.[line_width, max_categories, max_columns, max_colwidth,
 max_info_columns, max_info_rows, max_rows, max_seq_items, memory_usage,
 mpl_style, multi_sparse, notebook_repr_html, pprint_nest_depth, precision,
 show_dimensions]
- display.unicode.[ambiguous_as_wide, east_asian_width]
- display.[width]
- io.excel.xls.[writer]
- io.excel.xlsm.[writer]
- io.excel.xlsx.[writer]
- io.hdf.[default_format, dropna_table]
- mode.[chained_assignment, sim_interactive, use_inf_as_null]
Parameters
----------
pat : str
 Regexp which should match a single option.
 Note: partial matches are supported for convenience, but unless you use the
 full option name (e.g. x.y.z.option_name), your code may break in future
 versions if new options with similar names are introduced.
value :
 new value of option.
Returns
-------
None
Raises
------
OptionError if no such option exists
Notes
-----
The available options with its descriptions:
display.chop_threshold : float or None
 if set to a float value, all float values smaller then the given threshold
 will be displayed as exactly 0 by repr and friends.
 [default: None] [currently: None]
display.colheader_justify : 'left'/'right'
 Controls the justification of column headers. used by DataFrameFormatter.
 [default: right] [currently: right]
display.column_space No description available.
 [default: 12] [currently: 12]
display.date_dayfirst : boolean
 When True, prints and parses dates with the day first, eg 20/01/2005
 [default: False] [currently: False]
display.date_yearfirst : boolean
 When True, prints and parses dates with the year first, eg 2005/01/20
 [default: False] [currently: False]
display.encoding : str/unicode
 Defaults to the detected encoding of the console.
 Specifies the encoding to be used for strings returned by to_string,
 these are generally strings meant to be displayed on the console.
 [default: UTF-8] [currently: UTF-8]
display.expand_frame_repr : boolean
 Whether to print out the full DataFrame repr for wide DataFrames across
 multiple lines, `max_columns` is still respected, but the output will
 wrap-around across multiple "pages" if its width exceeds `display.width`.
 [default: True] [currently: True]
display.float_format : callable
 The callable should accept a floating point number and return
 a string with the desired format of the number. This is used
 in some places like SeriesFormatter.
 See formats.format.EngFormatter for an example.
 [default: None] [currently: None]
display.height : int
 Deprecated.
 [default: 60] [currently: 60]
 (Deprecated, use `display.max_rows` instead.)
display.large_repr : 'truncate'/'info'
 For DataFrames exceeding max_rows/max_cols, the repr (and HTML repr) can
 show a truncated table (the default from 0.13), or switch to the view from
 df.info() (the behaviour in earlier versions of pandas).
 [default: truncate] [currently: truncate]
display.latex.escape : bool
 This specifies if the to_latex method of a Dataframe uses escapes special
 characters.
 method. Valid values: False,True
 [default: True] [currently: True]
display.latex.longtable :bool
 This specifies if the to_latex method of a Dataframe uses the longtable
 format.
 method. Valid values: False,True
 [default: False] [currently: False]
display.latex.repr : boolean
 Whether to produce a latex DataFrame representation for jupyter
 environments that support it.
 (default: False)
 [default: False] [currently: False]
display.line_width : int
 Deprecated.
 [default: 80] [currently: 80]
 (Deprecated, use `display.width` instead.)
display.max_categories : int
 This sets the maximum number of categories pandas should output when
 printing out a `Categorical` or a Series of dtype "category".
 [default: 8] [currently: 8]
display.max_columns : int
 If max_cols 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 width of the terminal and print a truncated object which fits
 the screen width. 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: 20] [currently: 20]
display.max_colwidth : int
 The maximum width in characters of a column in the repr of
 a pandas data structure. When the column overflows, a "..."
 placeholder is embedded in the output.
 [default: 50] [currently: 200]
display.max_info_columns : int
 max_info_columns is used in DataFrame.info method to decide if
 per column information will be printed.
 [default: 100] [currently: 100]
display.max_info_rows : int or None
 df.info() will usually show null-counts for each column.
 For large frames this can be quite slow. max_info_rows and max_info_cols
 limit this null check only to frames with smaller dimensions than
 specified.
 [default: 1690785] [currently: 1690785]
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]
display.max_seq_items : int or None
 when pretty-printing a long sequence, no more then `max_seq_items`
 will be printed. If items are omitted, they will be denoted by the
 addition of "..." to the resulting string.
 If set to None, the number of items to be printed is unlimited.
 [default: 100] [currently: 100]
display.memory_usage : bool, string or None
 This specifies if the memory usage of a DataFrame should be displayed when
 df.info() is called. Valid values True,False,'deep'
 [default: True] [currently: True]
display.mpl_style : bool
 Setting this to 'default' will modify the rcParams used by matplotlib
 to give plots a more pleasing visual style by default.
 Setting this to None/False restores the values to their initial value.
 [default: None] [currently: None]
display.multi_sparse : boolean
 "sparsify" MultiIndex display (don't display repeated
 elements in outer levels within groups)
 [default: True] [currently: True]
display.notebook_repr_html : boolean
 When True, IPython notebook will use html representation for
 pandas objects (if it is available).
 [default: True] [currently: True]
display.pprint_nest_depth : int
 Controls the number of nested levels to process when pretty-printing
 [default: 3] [currently: 3]
display.precision : int
 Floating point output precision (number of significant digits). This is
 only a suggestion
 [default: 6] [currently: 6]
display.show_dimensions : boolean or 'truncate'
 Whether to print out dimensions at the end of DataFrame repr.
 If 'truncate' is specified, only print out the dimensions if the
 frame is truncated (e.g. not display all rows and/or columns)
 [default: truncate] [currently: truncate]
display.unicode.ambiguous_as_wide : boolean
 Whether to use the Unicode East Asian Width to calculate the display text
 width.
 Enabling this may affect to the performance (default: False)
 [default: False] [currently: False]
display.unicode.east_asian_width : boolean
 Whether to use the Unicode East Asian Width to calculate the display text
 width.
 Enabling this may affect to the performance (default: False)
 [default: False] [currently: False]
display.width : int
 Width of the display in characters. In case python/IPython is running in
 a terminal this can be set to None and pandas will correctly auto-detect
 the width.
 Note that the IPython notebook, IPython qtconsole, or IDLE do not run in a
 terminal and hence it is not possible to correctly detect the width.
 [default: 80] [currently: 80]
io.excel.xls.writer : string
 The default Excel writer engine for 'xls' files. Available options:
 'xlwt' (the default).
 [default: xlwt] [currently: xlwt]
io.excel.xlsm.writer : string
 The default Excel writer engine for 'xlsm' files. Available options:
 'openpyxl' (the default).
 [default: openpyxl] [currently: openpyxl]
io.excel.xlsx.writer : string
 The default Excel writer engine for 'xlsx' files. Available options:
 'xlsxwriter' (the default), 'openpyxl'.
 [default: xlsxwriter] [currently: xlsxwriter]
io.hdf.default_format : format
 default format writing format, if None, then
 put will default to 'fixed' and append will default to 'table'
 [default: None] [currently: None]
io.hdf.dropna_table : boolean
 drop ALL nan rows when appending to a table
 [default: False] [currently: False]
mode.chained_assignment : string
 Raise an exception, warn, or no action if trying to use chained assignment,
 The default is warn
 [default: warn] [currently: warn]
mode.sim_interactive : boolean
 Whether to simulate interactive mode for purposes of testing
 [default: False] [currently: False]
mode.use_inf_as_null : boolean
 True means treat None, NaN, INF, -INF as null (old way),
 False means None and NaN are null, but INF, -INF are not null
 (new way).
 [default: False] [currently: False]

以上这篇浅谈pandas中DataFrame关于显示值省略的解决方法就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持三水点靠木。

Python 相关文章推荐
Python中super关键字用法实例分析
May 28 Python
Python Socket实现简单TCP Server/client功能示例
Aug 05 Python
Tensorflow使用支持向量机拟合线性回归
Sep 07 Python
Python3安装psycopy2以及遇到问题解决方法
Jul 03 Python
Python计算两个矩形重合面积代码实例
Sep 16 Python
基于python操作ES实例详解
Nov 16 Python
django admin 添加自定义链接方式
Mar 11 Python
PyCharm License Activation激活码失效问题的解决方法(图文详解)
Mar 12 Python
使用Python Tkinter实现剪刀石头布小游戏功能
Oct 23 Python
python 带时区的日期格式化操作
Oct 23 Python
详解Python魔法方法之描述符类
May 26 Python
Python字符串格式化方式
Apr 07 Python
python3获取两个日期之间所有日期,以及比较大小的实例
Apr 08 #Python
python pandas中DataFrame类型数据操作函数的方法
Apr 08 #Python
python随机取list中的元素方法
Apr 08 #Python
Python实现的端口扫描功能示例
Apr 08 #Python
Python简单实现的代理服务器端口映射功能示例
Apr 08 #Python
pandas修改DataFrame列名的方法
Apr 08 #Python
Python数据分析库pandas基本操作方法
Apr 08 #Python
You might like
利用static实现表格的颜色隔行显示的代码
2007/09/02 PHP
PHP运行模式的深入理解
2013/06/03 PHP
php读取csv文件后,uft8 bom导致在页面上显示出现问题的解决方法
2013/08/10 PHP
php加密解密实用类分享
2014/01/07 PHP
php数组删除元素示例
2014/03/21 PHP
PHP的拦截器实例分析
2014/11/03 PHP
php中使用Ajax时出现Error(c00ce56e)的详细解决方案
2014/11/03 PHP
php+ajax实现无刷新分页的方法
2014/11/04 PHP
一个简单的js渐显(fadeIn)渐隐(fadeOut)类
2010/06/19 Javascript
javascript中创建对象的三种常用方法
2010/12/30 Javascript
为Javascript中的String对象添加去除左右空格的方法(示例代码)
2013/11/30 Javascript
jQuery选择器源码解读(七):elementMatcher函数
2015/03/31 Javascript
jQuery往返城市和日期查询实例讲解
2015/10/09 Javascript
详解基于Bootstrap扁平化的后台框架Ace
2015/11/27 Javascript
js导出excel文件的简洁方法(推荐)
2016/11/02 Javascript
Vue.2.0.5过渡效果使用技巧
2017/03/16 Javascript
jQuery实现radio第一次点击选中第二次点击取消功能
2017/05/15 jQuery
vue-cli 引入jQuery,Bootstrap,popper的方法
2018/09/03 jQuery
javascript实现画板功能
2020/04/12 Javascript
JS跨浏览器解析XML应用过程详解
2020/10/16 Javascript
适用于 Vue 的播放器组件Vue-Video-Player操作
2020/11/16 Javascript
[55:48]VGJ.S vs TNC Supermajor 败者组 BO3 第二场 6.6
2018/06/07 DOTA
Sanic框架路由用法实例分析
2018/07/16 Python
python 实现批量xls文件转csv文件的方法
2018/10/23 Python
python二维码操作:对QRCode和MyQR入门详解
2019/06/24 Python
夏尔巴人登珠峰品牌:Sherpa Adventure Gear
2018/02/08 全球购物
Otticanet意大利:最顶尖的世界名牌眼镜, 能得到打折季的价格
2019/03/10 全球购物
如何在发生故障的节点上重新安装 SQL Server
2013/03/14 面试题
大学生入党思想汇报
2014/01/01 职场文书
教师个人自我鉴定
2014/02/08 职场文书
大学生活动总结怎么写
2014/04/29 职场文书
会计求职信范文
2014/05/24 职场文书
开学第一天的感想
2015/08/10 职场文书
运动会主持人开幕词
2016/03/04 职场文书
Debian11 Xfce终端光标的颜色怎么设置?
2022/08/14 数码科技
Shell中的单中括号和双中括号的用法详解
2022/12/24 Servers