Pandas group-by and sum
<p>I am using this data frame:</p>

<pre><code>Fruit   Date    Name    Number
Apples  10/6/2016   Bob 7
Apples  10/6/2016   Bob 8
Apples  10/6/2016   Mike    9
Apples  10/7/2016   Steve   10
Apples  10/7/2016   Bob 1
Oranges 10/7/2016   Bob 2
Oranges 10/6/2016   Tom 15
Oranges 10/6/2016   Mike    57
Oranges 10/6/2016   Bob 65
Oranges 10/7/2016   Tony    1
Grapes  10/7/2016   Bob 1
Grapes  10/7/2016   Tom 87
Grapes  10/7/2016   Bob 22
Grapes  10/7/2016   Bob 12
Grapes  10/7/2016   Tony    15
</code></pre>

<p>I want to aggregate this by name and then by fruit to get a total number of fruit per name.</p>

<pre><code>Bob,Apples,16 ( for example )
</code></pre>

<p>I tried grouping by Name and Fruit but how do I get the total number of fruit.</p>

<p>Both the other answers accomplish what you want.  </p>

<p>You can use the <code>pivot</code> functionality to arrange the data in a nice table</p>

<pre><code>df.groupby(['Fruit','Name'],as_index = False).sum().pivot('Fruit','Name').fillna(0)



Name    Bob     Mike    Steve   Tom    Tony
Fruit                   
Apples  16.0    9.0     10.0    0.0     0.0
Grapes  35.0    0.0     0.0     87.0    15.0
Oranges 67.0    57.0    0.0     15.0    1.0
</code></pre>

python pandas dataframe group-by aggregate