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

时间:2021-05-22

控制台打印时显示的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 Cfirst 0.028208 0.992815 0.173891second 0.038683 0.645646 0.577595third 0.877076 0.149370 0.491027>>> df.round(2) A B Cfirst 0.03 0.99 0.17second 0.04 0.65 0.58third 0.88 0.15 0.49>>> df.round({'A': 1, 'C': 2}) A B Cfirst 0.0 0.992815 0.17second 0.0 0.645646 0.58third 0.9 0.149370 0.49>>> decimals = pd.Series([1, 0, 2], index=['A', 'B', 'C'])>>> df.round(decimals) A B Cfirst 0.0 1 0.17second 0.0 1 0.58third 0.9 0 0.49

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

声明:本页内容来源网络,仅供用户参考;我单位不保证亦不表示资料全面及准确无误,也不保证亦不表示这些资料为最新信息,如因任何原因,本网内容或者用户因倚赖本网内容造成任何损失或损害,我单位将不会负任何法律责任。如涉及版权问题,请提交至online#300.cn邮箱联系删除。

相关文章