美文网首页
python 保留三位小数

python 保留三位小数

作者: 清晨起床满满正能量_Go | 来源:发表于2019-03-13 15:47 被阅读0次
# -*- coding: utf-8 -*-
""" 保留三位小数
Created on Wed Mar 13 10:18:09 2019

@author: Administrator
"""

file_new=open('E:/Master_project/pq/atsnp_result.txt','w')
with open("E:/Master_project/pq/snp.txt") as f:
    next(f)
    nul=list()
    for line in f.readlines():
        c_array = line.split("\t")
        c_array[2]=round(float(c_array[2]),3)
        c_array[3]=round(float(c_array[3]),3)
        c_array[4]=round(float(c_array[4]),3)
        c_array[7]=round(float(c_array[7]),3)
        context = c_array[0]+'\t'+c_array[1]+'\t'+str(c_array[2])+'\t'+str(c_array[3])+'\t'+str(c_array[4])+'\t'+c_array[5]+'\t'+c_array[6]+'\t'+str(c_array[7])+'\n'
        file_new.write(context)
        print(line)
file_new.close()   
f.close()
图片.png
图片.png

相关文章

网友评论

      本文标题:python 保留三位小数

      本文链接:https://www.haomeiwen.com/subject/wuhtmqtx.html