python pandas, trying to find unique combinations of two columns and merging while summing a third column
<p>Hi I will show what im trying to do through examples:
I start with a dataframe like this:</p>

<pre><code>&gt; pd.DataFrame({'A':['a','a','a','c'],'B':[1,1,2,3], 'count':[5,6,1,7]})
    A   B   count
0   a   1   5
1   a   1   6
2   a   2   1
3   c   3   7
</code></pre>

<p>I need to find a way to get all the unique combinations between column A and B, and merge them. The count column should be added together between the merged columns, the result should be like the following:</p>

<pre><code>    A   B   count
0   a   1   11
1   a   2   1
2   c   3   7
</code></pre>

<p>Thans for any help.</p>

<p>Use <a href="http://pandas.pydata.org/pandas-docs/stable/generated/pandas.DataFrame.groupby.html" rel="nofollow"><code>groupby</code></a> with aggregating <a href="http://pandas.pydata.org/pandas-docs/stable/generated/pandas.core.groupby.GroupBy.sum.html" rel="nofollow"><code>sum</code></a>:</p>

<pre><code>print (df.groupby(['A','B'], as_index=False)['count'].sum())
   A  B  count
0  a  1     11
1  a  2      1
2  c  3      7

print (df.groupby(['A','B'])['count'].sum().reset_index())
   A  B  count
0  a  1     11
1  a  2      1
2  c  3      7
</code></pre>

python pandas group-by sum aggregate