How to calculate average number of entries for grouped data
<p>How can I calculate the <strong>average number</strong> of entries having <code>GRADE</code> equal to <code>4</code> and <code>5</code> for each group <code>&lt;Day,Hour&gt;</code>? For example, these should be average values fpr Day 1 and Hour 7 over months, for Day 1 and Hour 8 over months, etc.</p>

<pre><code>MONTH DAY  HOUR  GRADE
1     1    7     4
1     1    7     4
1     1    7     4
1     1    7     4
1     1    8     5
1     1    8     4
2     1    7     5
2     1    7     5
2     1    7     4
2     1    7     4
2     1    8     5
2     1    8     5
</code></pre>

<p>If I do this, it counts all entries for each group.</p>

<pre><code>grouped = df.groupby(['DAY','HOUR'], as_index=0)['GRADE'].agg(['count'])
</code></pre>

<p>However I need the output in the following format (the average values of <code>GRADE_4</code> and <code>GRADE_5</code> are invented):</p>

<pre><code>DAY  HOUR  GRADE_4  GRADE_5
1    7     25       41
1    8     37       42
</code></pre>