temp数据预处理--以24h为周期的噪声的序列

从数据库加载下来的是以5min取一次mean()的列,因此24h应取了24*60/5=288次数据

首先把这8352个数据(最后一个以倒数第二个填充)改成288*30的形式

txt=open('my_data.csv','r')
txt1=open('new_data.csv','w')
temp=[]
for line in txt.readlines():
    line=line.strip('\n')
    temp.append(line)

j=1
n=288
while n:
    s=[]
    for i in range(len(temp)):
        if (i+1)%288 == j:
            s.append(temp[i])
        else:
            pass
    for k in s:
        txt1.write(k)
        txt1.write(',')
    j=j+1
    n=n-1
    if j==288:
        s=[]
        txt1.write('\n')
        for i in range(len(temp)):
            if (i+1)%288 ==0:
                s.append(temp[i])
            else:
                pass       
        for k in s:
            txt1.write(k)
            txt1.write(',')
    else:
        pass
    txt1.write('\n')
    
txt.close()
txt1.close()

猜你喜欢

转载自www.cnblogs.com/stenci/p/10862189.html