title: Computing using groupby in python
body: <p>I have a sample dataframe <code>df</code> as shown below and I am using  <code>groupby</code> in python to solve where four columns <code>col</code> <code>alpha</code> <code>lambda</code> <code>n_fold</code> are equal then take sum of the <code>count</code> columns and perform mathematical operation like <code>(score*count)/sum(count)</code></p>
  
  <p>df = </p>
  
  <pre><code>    col   fold  alpha   lambda  score        n_fold count
  0   0.5      0    0        1    -0.424915241    1   3966
  1   0.5      1    0        1    -1.669508557    1   10182
  2   0.5      2    0        1    -0.157958626    1   17048
  3   0.75     0    0        1    -0.459086614    1   3966
  4   0.75     1    0        1    -1.830245577    1   10182
  5   0.75     2    0        1    -0.173278918    1   17048
  6   1        0    0        1    -0.442985033    2   3966
  7   1        1    0        1    -1.886578419    2   10182
  8   1        2    0        1    -0.18286539     2   17048
  </code></pre>
  
  <p>ouput:</p>
  
  <p><code>
       col    alpha   lambda  fold         final
  0   0.5       0       1      1     -0.685249027
  1   0.75      0       1      1     -0.750428163
  2   1         0       1      2     -0.772006323
  </code>
  I have tried below code but I am not able to solve. Is there anyway to solve this.</p>
  
  <p>Code: <code>df2 = (df.groupby(['sample', 'alpha', 'lambda', 'n_fold']).apply(lambda x: (x.score*x.count)/sum(count)).to_frame('final'))</code></p>