Pandas: Group by two columns to get sum of another column
<p>I look most of the previously asked questions but was not able to find answer for my question: </p>

<p>I have following data.frame</p>

<pre><code>           id   year month score num_attempts
0      483625  2010    01   50      1
1      967799  2009    03   50      1
2      213473  2005    09  100      1
3      498110  2010    12   60      1
5      187243  2010    01  100      1
6      508311  2005    10   15      1
7      486688  2005    10   50      1
8      212550  2005    10  500      1
10     136701  2005    09   25      1
11     471651  2010    01   50      1
</code></pre>

<p>I want to get following data frame </p>

<pre><code>year month sum_score sum_num_attempts
2009    03   50           1
2005    09  125           2
2010    12   60           1
2010    01  200           2
2005    10  565           3
</code></pre>

<p>Here is what I tried: </p>

<pre><code>sum_df = df.groupby(by=['year','month'])['score'].sum()
</code></pre>

<p>But this doesn't look efficient and correct. If I have more than one column need to be aggregate this seems like a very expensive call. for example if I have another column <code>num_attempts</code> and just want to sum by year month as score. </p>