微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

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

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

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

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

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

输出如下:

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

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

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

关于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,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,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,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关于显示值省略的解决方法就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持编程小技巧。

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐


使用爬虫利器 Playwright,轻松爬取抖查查数据 我们先分析登录的接口,其中 url 有一些非业务参数:ts、he、sign、secret。 然后根据这些参数作为关键词,定位到相关的 js 代码。 最后,逐步进行代码的跟踪,发现大部分的代码被混淆加密了。 花费了大半天,来还原这些混淆加密的代码
轻松爬取灰豚数据的抖音商品数据 调用两次登录接口实现模拟登录 我们分析登录接口,发现调用了两次不同的接口;而且,需要先调用 https://login.huitun.com/weChat/userLogin,然后再调用 https://dyapi.huitun.com/userLogin 接口。 登
成功绕过阿里无痕验证码,一键爬取飞瓜数据 飞瓜数据的登录接口,接入了阿里云的无痕验证码;通过接口方式模拟登录,难度比较高。所以,我们使用自动化的方式来实现模拟登录,并且获取到 cookie 数据。 [阿里无痕验证码] https://help.aliyun.com/document_detail/1
一文教你从零开始入门蝉妈妈数据爬取,成功逆向破解数据加密算法 通过接口进行模拟登录 我们先通过正常登录的方式,分析对应的登录接口。通过 F12 打开谷歌浏览器的调试面板,可以看到登录需要传递的一些参数;其中看到密码是被加密了。 不过我们通过经验可以大概猜测一下,应该是通过 md5 算法加密了。 接下
抽丝剥茧成功破解红人点集的签名加密算法 抽丝剥茧破解登录签名算法,成功实现模拟登录 headers = {} phone_num = "xxxx" password = "xxxx" md5_hash = hashlib.md5() md5_hash.upda
轻松绕过 Graphql 接口爬取有米有数的商品数据 有米有数数据的 API 接口,使用的是一种 API 查询语言 graphql。所有的 API 只有一个入口,具体的操作隐藏在请求数据体里面传输。 模拟登录,获取 sessionId 调用登录接口,进行模拟登录。 cookies = {} head
我最近重新拾起了计算机视觉,借助Python的opencv还有face_recognition库写了个简单的图像识别demo,额外定制了一些内容,原本想打包成exe然后发给朋友,不过在这当中遇到了许多小问题,都解决了,记录一下踩过的坑。 1、Pyinstaller打包过程当中出现warning,跟d
说到Pooling,相信学习过CNN的朋友们都不会感到陌生。Pooling在中文当中的意思是“池化”,在神经网络当中非常常见,通常用的比较多的一种是Max Pooling,具体操作如下图: 结合图像理解,相信你也会大概明白其中的本意。不过Pooling并不是只可以选取2x2的窗口大小,即便是3x3,
记得大一学Python的时候,有一个题目是判断一个数是否是复数。当时觉得比较复杂不好写,就琢磨了一个偷懒的好办法,用异常处理的手段便可以大大程度帮助你简短代码(偷懒)。以下是判断整数和复数的两段小代码: 相信看到这里,你也有所顿悟,能拓展出更多有意思的方法~
文章目录 3 直方图Histogramplot1. 基本直方图的绘制 Basic histogram2. 数据分布与密度信息显示 Control rug and density on seaborn histogram3. 带箱形图的直方图 Histogram with a boxplot on t