http://blog.csdn.net/pipisorry/article/details/49519545

):
print(df)

Note: 试了好久终于找到了这种设置方法!

它是这样实现的

class option_context(object):
    """
    >>> with option_context('display.max_rows', 10, 'display.max_columns', 5):

    """

    def __init__(self, *args):
):
            raise ValueError(
                'Need to invoke as'
                'option_context(pat, val, [(pat, val), ...)).'
            )

        ], ]))

    def __enter__(self):
        undo = []
        for pat, val in self.ops:
            undo.append((pat, _get_option(pat, silent=True)))

        self.undo = undo

        for pat, val in self.ops:
            _set_option(pat, val, silent=True)

    def __exit__(self, *args):
        if self.undo:
            for pat, val in self.undo:
                _set_option(pat, val, silent=True)

其实类似numpy数组输出精度的设置:[numpy输入输出]

pandas浮点数据输出禁用科学计数法的方式

with pd.option_context('display.float_format', lambda x: '%.3f' % x)

当然series也可以这样

Series(np.random.randn(3)).apply(lambda x: '%.3f' % x)

皮皮blog

pandas选项和设置

List of Options

Option Default Function
display.chop_threshold None If set to a float value, all floatvalues smaller then the giventhreshold will be displayed asexactly 0 by repr and friends.
display.colheader_justify right Controls the justification ofcolumn headers. used by DataFrameFormatter.
display.column_space 12 No description available.
display.date_dayfirst False When True, prints and parses dateswith the day first, eg 20/01/2005
display.date_yearfirst False When True, prints and parses dateswith the year first, eg 2005/01/20
display.encoding UTF-8 Defaults to the detected encodingof the console. Specifies the encodingto be used for strings returned byto_string, these are generally stringsmeant to be displayed on the console.
display.expand_frame_repr True Whether to print out the full DataFramerepr for wide DataFrames acrossmultiple lines,max_columns isstill respected, but the output willwrap-around across multiple “pages”if its width exceedsdisplay.width.
display.float_format None The callable should accept a floatingpoint number and return a string withthe desired format of the number.This is used in some places likeSeriesFormatter.See core.format.EngFormatter for an example.
display.height 60 Deprecated. Use display.max_rows instead.
display.large_repr truncate For DataFrames exceeding max_rows/max_cols,the repr (and HTML repr) can showa truncated table (the default from 0.13),or switch to the view from df.info()(the behaviour in earlier versions of pandas).allowable settings, [‘truncate’, ‘info’]
display.line_width 80 Deprecated. Use display.width instead.
display.max_columns 20 max_rows and max_columns are usedin __repr__() methods to decide ifto_string() or info() is used torender an object to a string. Incase python/IPython is running ina terminal this can be set to 0 andpandas will correctly auto-detectthe width the terminal and swap toa smaller format in case all columnswould not fit vertically. The IPythonnotebook, IPython qtconsole, or IDLEdo not run in a terminal and henceit is not possible to do correctauto-detection. ‘None’ value meansunlimited.
display.max_colwidth 50 The maximum width in characters ofa column in the repr of a pandasdata structure. When the column overflows,a ”...” placeholder is embedded inthe output.
display.max_info_columns 100 max_info_columns is used in DataFrame.infomethod to decide if per column informationwill be printed.
display.max_info_rows 1690785 df.info() will usually show null-countsfor each column. For large framesthis can be quite slow. max_info_rowsand max_info_cols limit this nullcheck only to frames with smallerdimensions then specified.
display.max_rows 60 This sets the maximum number of rowspandas should output when printingout various output. For example,this value determines whether therepr() for a dataframe prints outfully or just a summary repr.‘None’ value means unlimited.
display.max_seq_items 100 when pretty-printing a long sequence,no more then max_seq_items willbe printed. If items are omitted,they will be denoted by the additionof ”...” to the resulting string.If set to None, the number of itemsto be printed is unlimited.
display.memory_usage True This specifies if the memory usage ofa DataFrame should be displayed when thedf.info() method is invoked.
display.mpl_style None Setting this to ‘default’ will modifythe rcParams used by matplotlibto give plots a more pleasing visualstyle by default. Setting this toNone/False restores the values totheir initial value.
display.multi_sparse True “Sparsify” MultiIndex display (don’tdisplay repeated elements in outerlevels within groups)
display.notebook_repr_html True When True, IPython notebook willuse html representation forpandas objects (if it is available).
display.pprint_nest_depth 3 Controls the number of nested levelsto process when pretty-printing
display.precision 6 Floating point output precision interms of number of places after thedecimal, for regular formatting as wellas scientific notation. Similar tonumpy’sprecision print option
display.show_dimensions truncate Whether to print out dimensionsat the end of DataFrame repr.If ‘truncate’ is specified, onlyprint out the dimensions if theframe is truncated (e.g. not displayall rows and/or columns)
display.width 80 Width of the display in characters.In case python/IPython is running ina terminal this can be set to Noneand pandas will correctly auto-detectthe width. Note that the IPython notebook,IPython qtconsole, or IDLE do not run in aterminal and hence it is not possibleto correctly detect the width.
io.excel.xls.writer xlwt The default Excel writer engine for‘xls’ files.
io.excel.xlsm.writer openpyxl The default Excel writer engine for‘xlsm’ files. Available options:‘openpyxl’ (the default).
io.excel.xlsx.writer openpyxl The default Excel writer engine for‘xlsx’ files.
io.hdf.default_format None default format writing format, ifNone, then put will default to‘fixed’ and append will default to‘table’
io.hdf.dropna_table True drop ALL nan rows when appendingto a table
mode.chained_assignment warn Raise an exception, warn, or noaction if trying to use chainedassignment, The default is warn
mode.sim_interactive False Whether to simulate interactive modefor purposes of testing
mode.use_inf_as_null False True means treat None, NaN, -INF,INF as null (old way), False meansNone and NaN are null, but INF, -INFare not null (new way).

[Options and Settings]

pandas.set_option

pandas.set_option(pat,value) = <pandas.core.config.CallableDynamicDoc object at 0xb559f20c>

Sets the value of the specified option.

示例

[Python pandas, widen output display?]

to_csv精度设置

df_data.to_csv(outfile, index=False,
                   header=False, float_format='%11.6f')

[Print different precision by column with pandas.DataFrame.to_csv()]

from:http://blog.csdn.net/pipisorry/article/details/49519545

ref:pandas.core.config.get_option

pandas小记:pandas基本设置的更多相关文章

  1. pandas数组(pandas Series)-(4)NaN的处理

    上一篇pandas数组(pandas Series)-(3)向量化运算里说到,将两个 pandas Series 进行向量化运算的时候,如果某个 key 索引只在其中一个 Series 里出现,计算的 ...

  2. pandas数组(pandas Series)-(1)

    导入pandas import pandas as pd countries = ['Albania', 'Algeria', 'Andorra', 'Angola', 'Antigua and Ba ...

  3. [Pandas]利用Pandas处理excel数据

    Python 处理excel的第三包有很多,比如XlsxWriter.xlrd&xlwt.OpenPyXL.Microsoft Excel API等,最后综合考虑选用了Pandas. Pand ...

  4. pandas | 使用pandas进行数据处理——Series篇

    本文始发于个人公众号:TechFlow,原创不易,求个关注 上周我们关于Python中科学计算库Numpy的介绍就结束了,今天我们开始介绍一个新的常用的计算工具库,它就是大名鼎鼎的Pandas. Pa ...

  5. Pandas之:Pandas简洁教程

    Pandas之:Pandas简洁教程 目录 简介 对象创建 查看数据 选择数据 loc和iloc 布尔索引 处理缺失数据 合并 分组 简介 pandas是建立在Python编程语言之上的一种快速,强大 ...

  6. Pandas之:Pandas高级教程以铁达尼号真实数据为例

    Pandas之:Pandas高级教程以铁达尼号真实数据为例 目录 简介 读写文件 DF的选择 选择列数据 选择行数据 同时选择行和列 使用plots作图 使用现有的列创建新的列 进行统计 DF重组 简 ...

  7. pandas小记:pandas高级功能

    http://blog.csdn.net/pipisorry/article/details/53486777 pandas高级功能:面板数据.字符串方法.分类.可视化. 面板数据 {pandas数据 ...

  8. pandas小记:pandas时间序列分析和处理Timeseries

    http://blog.csdn.net/pipisorry/article/details/52209377 其它时间序列处理相关的包 [P4J 0.6: Periodic light curve ...

  9. pandas小记:pandas数据输入输出

    http://blog.csdn.net/pipisorry/article/details/52208727 数据输入输出 数据pickling pandas数据pickling比保存和读取csv文 ...

随机推荐

  1. C程序练习

    1.编程从键盘任意输入两个时间(例如4时55分和1时25分),计算并输出这两个时间之间的间隔.要求不输出时间差的负号. #include<stdio.h> int main() { int ...

  2. virtualenvwrapper 的安装和使用

    virtualenvwrapper是用来管理virtualenv的扩展包,用着很方便. 1. 安装: #安装virtualenv (sudo) pip install virtualenv #安装vi ...

  3. Rabbitmq集群

    分享到 一键分享 QQ空间 新浪微博 百度云收藏 人人网 腾讯微博 百度相册 开心网 腾讯朋友 百度贴吧 豆瓣网 搜狐微博 百度新首页 QQ好友 和讯微博 更多... 百度分享 Rabbitmq集群高 ...

  4. python笔记一(语言简介、解释器、输入输出)

    一.python语言简介 一顿狂吹python目前有多火.多NB,哈哈哈,不过用起来心情确实很舒畅. 解释性语言:缺点,运行速度慢. 二.python解释器 与C.C++.java不同,以上都需要先将 ...

  5. MLDS笔记:Optimization

    当函数空间覆盖到目标函数时,如何通过优化调整神经网络的参数找到这个目标函数呢? 深度学习中的损失函数是非凸的,非凸优化是个NP-hard问题,如何通过梯度下降来解决这个问题呢? 注意,不同于learn ...

  6. ACM Robot Motion

      机器人已被编程为按照其指令中的路径进行操作.机器人要移动的下一个方向的指令放在网格中.可能的指令是 N north (up the page) S south (down the page) E ...

  7. MongoDB 排序

    MongoDB sort()方法 在MongoDB中使用使用sort()方法对数据进行排序,sort()方法可以通过参数指定排序的字段,并使用 1 和 -1 来指定排序的方式,其中 1 为升序排列,而 ...

  8. Docker多台物理主机之间的容器互联

    Docker 默认的桥接网卡是 docker0.它只会在本机桥接所有的容器网卡,举例来说容器的虚拟网卡在主机上看一般叫做 veth* 而 Docker 只是把所有这些网卡桥接在一起,如下: [root ...

  9. 毕业论文内容框架指导-适用于MIS系统

    摘要: 背景.要做什么.选用什么技术.按照什么过程.原理.或者步骤去做.最后做出了什么东西.做出来的东西有什么用. 1. 前言 系统的背景与意义:为什么要做这个系统 ? 现状调查:别人做的怎么样? 系 ...

  10. 浅谈机器人控制与仿真设计----RDS和ROS

    机器人控制.仿真或实验,主要由三个部分组成,机器人.环境和算法. 当然各部分又包含很多子部分和功能,这里主要以仿真为主,为了使得仿真结果能够直接应用到实际机器人上,这里分别以RDS和ROS对比介绍.h ...