title: Pandas groupby nlargest sum
body: <p>I am trying to use <code>groupby</code>, <code>nlargest</code>, and <code>sum</code> functions in Pandas together, but having trouble making it work. </p>
  
  <pre><code>State    County    Population
  Alabama  a         100
  Alabama  b         50
  Alabama  c         40
  Alabama  d         5
  Alabama  e         1
  ...
  Wyoming  a.51      180
  Wyoming  b.51      150
  Wyoming  c.51      56
  Wyoming  d.51      5
  </code></pre>
  
  <p>I want to use <code>groupby</code> to select by state, then get the top 2 counties by population. Then use only those top 2 county population numbers to get a sum for that state. </p>
  
  <p>In the end, I'll have a list that will have the state and the population (of it's top 2 counties). </p>
  
  <p>I can get the <code>groupby</code> and <code>nlargest</code> to work, but getting the sum of the <code>nlargest(2)</code> is a challenge. </p>
  
  <p>The line I have right now is simply: <code>df.groupby('State')['Population'].nlargest(2)</code></p>