title: How to calculate moving average for temperature?
body: <p>This is the output I need:</p>
  <pre class="lang-none prettyprint-override"><code>Temperature anomaly filename:SacramentoTemps.csv
  Enter window size:60
  1940,-0.2331
  1941,-0.2169
  1942,-0.2150
  1943,-0.2228
  1944,-0.2107
  1945,-0.1796
  1946,-0.1667
  1947,-0.1582
  1948,-0.1585
  1949,-0.1492
  1950,-0.1711
  1951,-0.1688
  1952,-0.1490
  1953,-0.1556
  1954,-0.1548
  1955,-0.1580
  1956,-0.1420
  1957,-0.1101
  1958,-0.1017
  </code></pre>
  <p>This is my code:</p>
  <pre><code>filename = input(&quot;Temperature anomaly filename:&quot;)
  infile = open(filename, &quot;r&quot;)
  k = int(input(&quot;Enter window size:&quot;))
  infile.readline()
  
  temp_list = []
  
  
  for line in infile:
     line = line.strip()
     year,temp = line.split(&quot;,&quot;)
     temp = float(temp)
     temp_list.append(temp)
  
      index = k
  for index in range(index,len(temp_list)-1-index):
      year = 1880 + index
      ave = sum(temp_list[index:index+k]) / (2*index+1)
      print(str(year)+&quot;,&quot;+&quot;{:.4f}&quot;.format(ave))
  infile.close()
  </code></pre>
  <p>My code currently prints out up until the year 1957 and it prints out the wrong averages for each year. What do I need to fix?</p>