python改变列表数字小数位数_python对时间序列处理时数据小数位数混乱

想对时间序列进行状态划分,时间序列最大值1.8,最小值-0.5,划分为115个状态区间,每个状态区间宽度为0.02,把处于各状态区间的值化成区间中间的值,写了一段代码,但是得到的值有的小数位数很奇怪,请大神帮忙解惑,谢谢

__author__ = 'Administrator'

file = open('yij.txt','r')

while 1:

line = file.readline()

a = line.split()

m=0

b=[-0.5,-0.48,-0.46,-0.44,-0.42,-0.40,-0.38,-0.36,-0.34,-0.32,-0.30,-0.28,-0.26,-0.24,-0.22,-0.20,-0.18,-0.16,-0.14,-0.12,-0.10,-0.08,-0.06,-0.04,-0.02,0.00,0.02,

0.04,0.06,0.08,0.10,0.12,0.14,0.16,0.18,0.20,0.22,0.24,0.26,0.28,0.30,0.32,0.34,0.36,0.38,0.40,0.42,0.44,0.46,0.48,0.50,0.52,0.54,0.56,0.58,0.60,0.62,0.64,

0.66,0.68,0.70,0.72,0.74,0.76,0.78,0.80,0.82,0.84,0.86,0.88,0.90,0.92,0.94,0.96,0.98,1.00,1.02,1.04,1.06,1.08,1.10,1.12,1.14,1.16,1.18,1.20,1.22,1.24,1.26,1.28,

1.30,1.32,1.34,1.36,1.38,1.40,1.42,1.44,1.46,1.48,1.50,1.52,1.54,1.56,1.58,1.60,1.62,1.64,1.66,1.68,1.70,1.72,1.74,1.76,1.78,1.80]

if line != '':

file1 = open('yij_state.txt', 'a+')

for i in b:

if i

file1.write("%.2f\n" % (i+0.01))

if float(a[0])<=-0.5:

file1.write("%.2f\n" % (-0.49))

elif float(a[0])>1.8:

file1.write("%.2f\n" % (1.79))

break

file1.close

else:

break

file.close

代码已经改正确了

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值