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>You can use <code>groupby</code> and <code>sum</code>:</p>

<pre><code>df.groupby(['Name', 'Fruit']).sum()

               Number
Name  Fruit          
Bob   Apples       16
      Grapes       35
      Oranges      67
Mike  Apples        9
      Oranges      57
Steve Apples       10
Tom   Grapes       87
      Oranges      15
Tony  Grapes       15
      Oranges       1
</code></pre>

python pandas dataframe group-by aggregate