计算numpy数组的月平均值?

时间:2015-03-27 05:49:27

标签: python csv numpy

我有两个csv文件,每日数据跨越1950-1990,列如下所示:

文件1:

year  month day value
1950    2   27  1.693   
1950    2   28  0       
1950    3   1   0.016   
1950    3   2   0.067   

file2的:

1950    2   27  0
1950    2   28  0.08
1950    3   1   0.05
1950    3   2   0

我想在两个文件中采用第4列的月平均值。如果file1中的月平均值低于0.01,则写入两个新阵列(每月平均值> 0.01且<0.01的每日值)。此外,使用新创建的数组的索引来创建两个新的file2数组。我正在尝试使用以下内容而不是每月平均值返回数组的最后每日值:

import numpy as np
import csv

time = [] ; f1 = [] ; f2 = []
with open('file1.csv','rb') as csvfile:
    reader=csv.reader(csvfile)
    for row in reader:
        time.append(row[1])
        f1.append(row[3])

with open('file2.csv','rb') as csvfile:    
    reader=csv.reader(csvfile)
    for row in reader:
        f2.append(row[3]) 

f1_arr = np.array(f1)
f2_arr = np.array(f2)
x = f1_arr.astype(np.float) # convert string to float
y = f2_arr.astype(np.float)
for ii in xrange(len(time)):
    if ii == ii:
        monthly_mean = np.mean(x[ii])

请建议如何修复它并分开数组。

0 个答案:

没有答案
相关问题