title: Compute monthly mean of numpy array?
body: <p>I have two csv files with daily data spanning from 1950-1990 and columns as shown below:</p>
  
  <p>file1:</p>
  
  <pre><code>year  month day value
  1950    2   27  1.693   
  1950    2   28  0       
  1950    3   1   0.016   
  1950    3   2   0.067   
  </code></pre>
  
  <p>file2:</p>
  
  <pre><code>1950    2   27  0
  1950    2   28  0.08
  1950    3   1   0.05
  1950    3   2   0
  </code></pre>
  
  <p>I want to take monthly mean of column 4 in both files. If monthly mean value in file1 is below 0.01 then write two new arrays (daily values with monthly mean > 0.01 and &lt; 0.01). Also, use index of newly created arrays to create two new arrays of file2. I am trying with following which instead of monthly mean returns last daily value of array:</p>
  
  <pre><code>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])
  </code></pre>
  
  <p>Please suggest how to fix it and separate arrays.</p>