读数据
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(',')
if ' ' in temp:
print("temp: ", temp)
print(count, end='')
aa.append(temp)
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)))