title: Python CSV - Need to Group and Calculate values based on one key
body: <p>I have a simple 3 column csv file that i need to use python to group each row based on one key, then average the values for another key and return them. File is standard csv format, set up as so;</p>
  
  <pre><code>ID, ZIPCODE, RATE
  1, 19003, 27.50
  2, 19003, 31.33
  3, 19083, 41.4
  4, 19083, 17.9
  5, 19102, 21.40
  </code></pre>
  
  <p>So basically what I need to do is calculate the average rate col[2] for each unique zipcode col[1] in that file and return the results. So get average rate for all records in 19003, 19083, and so on.</p>
  
  <p>I've looked at using csv module and reading the file into a dictionary, then sorting the dict based on unique values in the zipcode col but can't seem to make any progress. </p>
  
  <p>Any help/suggestions appreciated.</p>