Python数据集基本处理

读数据

def read_file_byLine(fileName):
    aa=[]
    file_object = open(fileName)
    try:
        count = 0
        for line in file_object:
            temp = line.replace("\t", "").replace("\n", "").replace("[", "").replace("'", "").replace("]", "").split(',')
            # temp = line.split()
            if ' ' in temp:
                print("temp: ", temp)
                print(count, end='')
            aa.append(temp)
        # input = np.array(aa)
    finally:
        file_object.close()
    return aa

划分time-series

dataset0 = read_file_byLine("D:/A程序文件/python/gas/20160930.txt")
dataset1 = read_file_byLine("D:/A程序文件/python/gas/20161001.txt")
dataset2 = read_file_byLine("D:/A程序文件/python/gas/20161003.txt")
whole_file = "D:/A程序文件/python/gas/whole_gas.txt"
 time = dataset[:,0]
 for i in range(200):
      tmp_file = dir + 'time_series/c_' + str(i) + '.txt'
      with open(tmp_file,"w") as f:
        for j in range(29):
            b = dataset0[j*10000+i]
            f.write(str(b[1:19]))
            f.write('\n')
        for j in range(29):
            c = dataset1[j * 10000 + i]
            f.write(str(c[1:19]))
            f.write('\n')
        for j in range(29):
            d = dataset2[j*10000+i]
            f.write(str(d[1:19]))
            f.write('\n')
      f.close()

整合whole文件

with open(whole_file, "w") as c:
     for i in range(200):
         tmp_file = dir + 'time_series/c_' + str(i) + '.txt'
         with open(tmp_file, "r") as f:
             tempdata = f.read()
             c.write(tempdata)
         f.close()
     c.close()

求数据最大值最小值list均值

 data = read_file_byLine(whole_file)
print(min(data))
print(max(data))
temp = np.array(data)
print(sum(np.asarray(temp, dtype=float)) / float(len(temp)))
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值