python科学数据分析_python数据分析-科学计数法

用python进行数据分析时,查看数据,经常发生数据被自动显示成科学记数法的模式,或者多行多列数据只显示前后几行几列,中间都是省略号的情形。

numpy

import numpy as npnp.set_printoptions(suppress=True, threshold=np.nan)

suppress=True 取消科学记数法

threshold=np.nan 完整输出(没有省略号)

pandas

display.[max_categories, max_columns, max_colwidth, max_info_columns, max_info_rows, max_rows, max_seq_items, memory_usage, multi_sparse, notebook_repr_html, pprint_nest_depth, precision, show_dimensions]

可以在pd.set_option设置display.float_format参数来以政策小数显示,比如下面设置显示到小数点后3位

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

set_option中还有其它一些控制设置,包括默认显示列数,行数等等

pd.set_option('display.max_columns',5, 'display.max_rows', 100)

import pandas as pdpd.set_option('display.max_columns', 10000, 'display.max_rows', 10000)

display.max_columns 显示最大列数

display.max_rows 显示最大行数

1、pd.set_option(‘expand_frame_repr’, False)

True就是可以换行显示。设置成False的时候不允许换行

2、pd.set_option(‘display.max_rows’, 10)

pd.set_option(‘display.max_columns’, 10)

显示的最大行数和列数,如果超额就显示省略号,这个指的是多少个dataFrame的列。如果比较多又不允许换行,就会显得很乱。

3、pd.set_option(‘precision’, 5)

显示小数点后的位数

4、pd.set_option(‘large_repr’, A)

truncate表示截断,info表示查看信息,一般选truncate

5、pd.set_option(‘max_colwidth’, 5)

列长度

6、pd.set_option(‘chop_threshold’, 0.5)

绝对值小于0.5的显示0.0

7、pd.set_option(‘colheader_justify’, ‘left’)

显示居中还是左边,

8、pd.set_option(‘display.width’, 200)

横向最多显示多少个字符, 一般80不适合横向的屏幕,平时多用200.

np.set_printoptions

np.set_printoptions(precision=None, threshold=None, edgeitems=None, linewidth=None, suppress=None, nanstr=None, infstr=None, formatter=None)

参数:

precision 设置浮点数的精度 (默认值:8)

threshold 设置显示的数目(超出部分省略号显示, np.nan是完全输出,默认值:1000)

edgeitems 设置显示前几个,后几个 (默认值:3)

suppress 设置是否科学记数法显示 (默认值:False)

示例如下:

import numpy as npnp.set_printoptions(precision=4, threshold=8, edgeitems=4, linewidth=75, suppress=True, nanstr='nan', infstr='inf')print("precision=4, 浮点数精确小数点后4位: ", np.array([1.23446789]))print("threshold=8, edgeitems=4, 显示8个,前4后4: ", np.arange(10))np.set_printoptions(formatter={'all': lambda x :'int:'+str(-x)})print("formatter, 格式化输出: ", np.arange(5))

输出如下:

[图片上传失败...(image-15f596-1587702700460)]

注意:precision自动四舍五入

pd.set_option

pd.set_option(pat, value)

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值