title: Getting averages from monthly data
body: <p>I have a file with about 2000 lines of Data on sunspots. I need to take each month and find the average of it and write it to a new file. How do I group the months so I can get a average? I've read a few threads suggesting using panda, but since we haven't got there yet in class, I'd rather not use it without having a full grasp of what it does. </p>
  
  <p>So far, my code separates the years and months and the days. How do I group the months together to find the average sunspots?</p>
  
  <p>Here is my code so far:</p>
  
  <pre><code>def OpenFile(File):
      outfile = open ("Monthlytemp.txt","w")
  
      try:
          Lines= open(File).readlines()
      except IOError:
          Lines=[]
      for line in Lines:
          Dates = line.split()
          Year= str(Dates[0][0:4])
          Month = str(Dates[0][4:6])
          Date = str(Dates [0][6:8])
          Spots = int(Dates [2])
          if Spots == 999:
              Spots= ''
          Spots = str(Spots)
          Data = [Year, Month, Date, Spots, '\n']
          Data = ' '.join(Data)
          outfile.write(str(Data))
          #print (Data)
      outfile.close()
      return Data
  </code></pre>