我有这个程序来读取数据,平均三行然后平均向下列,到目前为止它做得很好。但是,我现在正尝试返回并删除负数据点,但遇到了一些麻烦:
from __future__ import division
import csv
v = open("Pt_2_Test_Data.csv", 'wb') #created file to write output to
A =[]
B = []
with open("test2.xls") as w:
w.next() # skip over header row
for row in w:
(date, time, a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s, t,
u, LZA, SZA, LAM) = row.split("\t") # split columns into fields
A.append([(float(a) + float(b) + float(c))/3,
(float(d) + float(e) + float(f))/3,
(float(g) + float(h) + float(i))/3,
(float(j) + float(k) + float(l))/3,
(float(m) + float(n) + float(o))/3,
(float(p) + float(q) + float(r))/3,
(float(s) + float(t) + float(u))/3])
def mean(B):
return sum(B) / len(B)
for x in A:
if x > 0:
B.append(x)
print B
C = map(mean, zip(*B))
print C
v.close()
(我还不担心将数据写入文件,只是在获取最终平均值之前摆脱负数。)