当前位置: 移动技术网 > IT编程>脚本编程>Python > pandas 小数位数 精度的处理方法

pandas 小数位数 精度的处理方法

2018年08月19日  | 移动技术网IT编程  | 我要评论

zjrc,杜存刚,香港金道贵金属有限公司

控制台打印时显示的2位小数:

pd.set_option('precision', 2)

实际修改数据精度:

官例:

>>> df = pd.dataframe(np.random.random([3, 3]),
...  columns=['a', 'b', 'c'], index=['first', 'second', 'third'])
>>> df
    a   b   c
first 0.028208 0.992815 0.173891
second 0.038683 0.645646 0.577595
third 0.877076 0.149370 0.491027
>>> df.round(2)
   a  b  c
first 0.03 0.99 0.17
second 0.04 0.65 0.58
third 0.88 0.15 0.49
>>> df.round({'a': 1, 'c': 2})
   a   b  c
first 0.0 0.992815 0.17
second 0.0 0.645646 0.58
third 0.9 0.149370 0.49
>>> decimals = pd.series([1, 0, 2], index=['a', 'b', 'c'])
>>> df.round(decimals)
   a b  c
first 0.0 1 0.17
second 0.0 1 0.58
third 0.9 0 0.49

以上这篇pandas 小数位数 精度的处理方法就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持移动技术网。

如对本文有疑问,请在下面进行留言讨论,广大热心网友会与你互动!! 点击进行留言回复

相关文章:

验证码:
移动技术网