title: Group by column and add columns to count for occurences of values
body: <p>I have the following code:</p>
  <pre><code>import numpy as np
  from random import randrange
  
  groups = [randrange(1,8) for x in range(50)]
  df = pd.DataFrame(groups,columns = [&quot;group&quot;])
  df[&quot;dummy1&quot;] = pd.Series(np.random.randint(20,size = len(df)))
  df[&quot;dummy2&quot;] = pd.Series(np.random.randint(20,size = len(df)))
  </code></pre>
  <p>Grouping the data is obvious, let's say like this:</p>
  <pre><code>groups = df.groupby(&quot;group&quot;).agg({&quot;dummy1&quot;:[np.sum,np.mean]})
  </code></pre>
  <p>However i want to count the occurences of specific values in <code>df[&quot;dummy1&quot;]</code> for example. And in the groups i want to have a column that shows the count for each value. For example like this:</p>
  <p>I want to have something like this:</p>
  <pre><code>      dummy1            count_1 count_3
           sum       mean                
  group                                  
  1        128   9.846154       2       1
  2         70  10.000000       4       3
  3         89  12.714286       2       3
  4         65   8.125000       4       4
  5         93  15.500000       4       3
  6         69  11.500000       3       1
  7         31  10.333333       4       2
  </code></pre>
  <p>Is there any easy way to do this? I tried a solution of just adding new columns that show if the <code>df[&quot;dummy1&quot;]</code> value is for example 1 and then use a sum on the column while aggregating the groups. However, this is insanely slow for even my dataset with around 100k entries.</p>