title: Python: how to translate complex SQL aggregate statements into pandas?
body: <p>With pandas, what is the best way to create the equivalent of a SQL group by statement, using:</p>
  
  <ul>
  <li>a different aggregate function on each field (e.g. I need the sum of
  field1, the avg of field2 and the max of field3)</li>
  <li>slightly more
  complex calculations like sum(field1) / sum(field2), e.g. for weighted
  averages</li>
  </ul>
  
  <p>Say I have a table with data at the city level and I want to aggregate it by country and region. In SQL I'd write:</p>
  
  <pre><code>select Country, Region
  , count(*) as '# of cities'
  ,sum(GDP) as GDP
  ,avg(Population) as 'avg # inhabitants per city'
  ,sum(male_population) / sum(Population) as '% of male population'
  from CityTable
  group by Country, Region
  </code></pre>
  
  <p>How can I do the same in pandas? Thank you!</p>