title: python pivot and average a dirty dateframe
body: <p>I have homicide statistic 2003-2008 as csv file in python. </p>
  
  <p>The problem is there is more rate values for the same year from different sources. 
  For example homicide rate in US in 2004 is from 3 different sources. (3 values for the same year)</p>
  
  <p>1-I would like to calculate the average of Rate per year for every country. Then I have a single rate for every country in every year.</p>
  
  <p>2-Then I want to pivot rate per year to new columns. (column name: 2013 - value in row 12354 as rate)</p>
  
  <p>*What matters to me is that the index should be number not country names. (0,1,...)</p>
  
  <pre><code>columns = ['country','rate','year','source']
  df = pd.DataFrame(columns=columns)
  df.loc[0] = ['US',25.0,2003,'international']
  df.loc[1] = ['US',30,2003,'goverment']
  df.loc[2] = ['US',35,2005,'goverment']
  df.loc[3] = ['China',12.0,2004,'goverment']
  df.loc[4] = ['China',15.0,2004,'international']
  
  
  df.head()
      country rate    year    source
  0   US     25.0     2003    international
  1   US     30.0     2003    goverment
  2   US     35.0     2005    goverment
  3   China   12.0    2004    goverment
  4   China   15.0    2004    international
  </code></pre>
  
  <p>Expected answer1:</p>
  
  <pre><code>   country  rate    year    
  0   US     27.5     2003    
  1   US     35.0     2005       
  2   China   13.5    2004    
  </code></pre>
  
  <p>Expected answer2:</p>
  
  <pre><code>   country  2003  2004   2005   
  0   US      27.5         35 
  1   China          13.5 
  </code></pre>