title: Creating bins of a column and getting the count in pandas
body: <p>i have a pandas dataframe:</p>
  
  <pre><code>item_code    price
     1           15
     1           30
     1           60
     2           50
     3           90
     4           110
     5           130
     4           150
  </code></pre>
  
  <p>We can see that the max price is 150. i want to divide it into 5 bins of 30 each(into new columns) and get the count of occurance of each item code in that price bin.</p>
  
  <p>final df=</p>
  
  <pre><code>item_code    0-30    31-60    61-90    91-120    121-150
      1         2         1       0         0          0
      2         0         1       0         0          0
      3         0         0       1         0          0
      4         0         0       0         1          1
      5         0         0       0         0          1
  </code></pre>
  
  <p>i.e <code>item_code 1</code> falls twice in the price range 0-30 therefore under column <code>0-30</code> put count as 2. <code>item_code 1</code> falls once in price range 31-60. Therefore put count as 1.... Similarly for other item codes.</p>
  
  <p>I tried using pd.cut</p>
  
  <pre><code>bins = [0, 30, 60, 90, 120,150]
  df2 = pd.cut(df['price'], bins)
  </code></pre>
  
  <p>But it did not work.</p>