title: Pandas groupby with bin counts
body: <p>I have a DataFrame that looks like this:</p>
  
  <pre><code>+----------+---------+-------+
  | username | post_id | views |
  +----------+---------+-------+
  | john     |       1 |     3 |
  | john     |       2 |    23 |
  | john     |       3 |    44 |
  | john     |       4 |    82 |
  | jane     |       7 |     5 |
  | jane     |       8 |    25 |
  | jane     |       9 |    46 |
  | jane     |      10 |    56 |
  +----------+---------+-------+
  </code></pre>
  
  <p>and I would like to transform it to count views that belong to certain bins like this:</p>
  
  <pre><code>+------+------+-------+-------+--------+
  |      | 1-10 | 11-25 | 25-50 | 51-100 |
  +------+------+-------+-------+--------+
  | john |    1 |     1 |     1 |      1 |
  | jane |    1 |     1 |     1 |      1 |
  +------+------+-------+-------+--------+
  </code></pre>
  
  <p>I tried:</p>
  
  <pre><code>bins = [1, 10, 25, 50, 100]
  groups = df.groupby(pd.cut(df.views, bins))
  groups.username.count()
  </code></pre>
  
  <p>But it only gives aggregate counts and not counts by user. How can I get bin counts by user?</p>
  
  <p>The aggregate counts (using my real data) looks like this:</p>
  
  <pre><code>impressions
  (2500, 5000]         2332
  (5000, 10000]        1118
  (10000, 50000]        570
  (50000, 10000000]      14
  Name: username, dtype: int64
  </code></pre>