Count occurences in DataFrame
<p>I've a Dataframe in this format:</p>

<pre><code>| Department | Person | Power  | ... |
|------------|--------|--------|-----|
| ABC        | 1234   |  75    | ... |
| ABC        | 1235   |  25    | ... |
| DEF        | 1236   |  50    | ... |
| DEF        | 1237   | 100    | ... |
| DEF        | 1238   |  25    | ... |
| DEF        | 1239   |  50    | ... |
</code></pre>

<p>What I now want to get is the sum of occurences for each value in the power column. How can I get this from my DataFrame?</p>

<pre><code>| Department | 100 |  75 |  50 |  25 |
|------------|-----|-----|-----|-----|
| ABC        |   0 |   1 |   0 |   1 |
| DEF        |   1 |   0 |   2 |   1 |
</code></pre>

<p>or it can be done this way:</p>

<pre><code>&gt;&gt;&gt; df.groupby(['Department','Power']).count().unstack().fillna(0)

           Person               
Power         25   50   75   100
Department                      
ABC           1.0  0.0  1.0  0.0
DEF           1.0  2.0  0.0  1.0
</code></pre>

python pandas pivot-table reshape crosstab