pandas 小数位数 精度的处理方法
更新时间:2018年06月09日 09:24:51 作者:小白的2015
今天小编就为大家分享一篇pandas 小数位数 精度的处理方法,具有很好的参考价值,希望对大家有所帮助。一起跟随小编过来看看吧
控制台打印时显示的2位小数:
pd.set_option('precision', 2)
实际修改数据精度:
官例:http://pandas.pydata.org/pandas-docs/stable/generated/pandas.DataFrame.round.html
>>> 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 小数位数 精度的处理方法就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持脚本之家。
相关文章
Python如何使用bokeh包和geojson数据绘制地图
这篇文章主要介绍了Python如何使用bokeh包和geojson数据绘制地图,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友可以参考下2020-03-03


最新评论