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
ABC
first0.0282080.9928150.173891
second0.0386830.6456460.577595
third0.8770760.1493700.491027
>>>df.round(2)
ABC
first0.030.990.17
second0.040.650.58
third0.880.150.49
>>>df.round({'A':1,'C':2})
ABC
first0.00.9928150.17
second0.00.6456460.58
third0.90.1493700.49
>>>decimals=pd.Series([1,0,2],index=['A','B','C'])
>>>df.round(decimals)
ABC
first0.010.17
second0.010.58
third0.900.49
以上这篇pandas小数位数精度的处理方法就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持毛票票。
声明:本文内容来源于网络,版权归原作者所有,内容由互联网用户自发贡献自行上传,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任。如果您发现有涉嫌版权的内容,欢迎发送邮件至:czq8825#qq.com(发邮件时,请将#更换为@)进行举报,并提供相关证据,一经查实,本站将立刻删除涉嫌侵权内容。