title: groupby weighted average and sum in pandas dataframe
body: <p>I have a dataframe:</p>
  <pre><code>    Out[78]: 
     contract month year  buys  adjusted_lots    price
  0         W     Z    5  Sell             -5   554.85
  1         C     Z    5  Sell             -3   424.50
  2         C     Z    5  Sell             -2   424.00
  3         C     Z    5  Sell             -2   423.75
  4         C     Z    5  Sell             -3   423.50
  5         C     Z    5  Sell             -2   425.50
  6         C     Z    5  Sell             -3   425.25
  7         C     Z    5  Sell             -2   426.00
  8         C     Z    5  Sell             -2   426.75
  9        CC     U    5   Buy              5  3328.00
  10       SB     V    5   Buy              5    11.65
  11       SB     V    5   Buy              5    11.64
  12       SB     V    5   Buy              2    11.60
  </code></pre>
  <p>I need a sum of adjusted_lots   , price which is weighted average , of price and adjusted_lots , grouped by all the other columns , ie. grouped by (contract, month , year and buys)</p>
  <p>Similar solution on R was achieved by following code, using dplyr, however unable to do the same in pandas.</p>
  <pre><code>&gt; newdf = df %&gt;%
    select ( contract , month , year , buys , adjusted_lots , price ) %&gt;%
    group_by( contract , month , year ,  buys) %&gt;%
    summarise(qty = sum( adjusted_lots) , avgpx = weighted.mean(x = price , w = adjusted_lots) , comdty = &quot;Comdty&quot; )
  
  &gt; newdf
  Source: local data frame [4 x 6]
  
    contract month year comdty qty     avgpx
  1        C     Z    5 Comdty -19  424.8289
  2       CC     U    5 Comdty   5 3328.0000
  3       SB     V    5 Comdty  12   11.6375
  4        W     Z    5 Comdty  -5  554.8500
  </code></pre>
  <p>is the same possible by groupby or any other solution ?</p>