One - One Code All

Blog Content

pandas中Dataframe中小数的保留小数点后两位

Python 统计学-科学计算   2011-08-08 22:29:57

直接循环:
for i in range(1,n):
    for j in range(1,n):
        b.ix[i][j]=float('%.2f' %b.ix[i][j])

formater="{0:.03f}".format  
df.applymap(formater)  

print 打印时的精度,可以用:
pd.set_option(‘precision’, n) # n是要显示的小数位数,应该是一个整数

导出数据时希望保存的文件更小,你可以:
data.to_csv('out.csv',index = False, float_format = '%.4f')


上一篇:pandas的to_csv()使用方法
下一篇:python中requests配置超时及重试次数

The minute you think of giving up, think of the reason why you held on so long.