title: How to categorize data based on column values in pandas?
body: <p>Let say I have this dataframe:</p>
  
  <pre><code>raw_data = {'regiment': ['Nighthawks', 'Nighthawks', 'Nighthawks', 'Nighthawks', 'Dragoons', 'Dragoons', 'Dragoons', 'Dragoons', 'Scouts', 'Scouts', 'Scouts', 'Scouts'], 
          'payout': [.1, .15, .2, .3, 1.2, 1.3, 1.45, 2, 2.04, 3.011, 3.45, 1], 
          'name': ['Miller', 'Jacobson', 'Ali', 'Milner', 'Cooze', 'Jacon', 'Ryaner', 'Sone', 'Sloan', 'Piger', 'Riani', 'Ali'], 
          'preTestScore': [4, 24, 31, 2, 3, 4, 24, 31, 2, 3, 2, 3],
          'postTestScore': [25, 94, 57, 62, 70, 25, 94, 57, 62, 70, 62, 70]}
  df = pd.DataFrame(raw_data, columns = ['regiment', 'payout', 'name', 'preTestScore', 'postTestScore'])
  </code></pre>
  
  <p>Now, I want to build these categories based on the column "payout":</p>
  
  <pre><code>Cat1 : 0 &lt;= x &lt;= 1
  Cat2 : 1 &lt;  x &lt;= 2
  Cat3 : 2 &lt;  x &lt;= 3
  Cat4 : 3 &lt;  x &lt;= 4
  </code></pre>
  
  <p>and build the sum of the column <code>postTestscore</code></p>
  
  <p>I do it this way, using the boolean indexing:</p>
  
  <pre><code>df.loc[(df['payout'] &gt; 0) &amp; (df['payout'] &lt;= 1), 'postTestScore'].sum()
  df.loc[(df['payout'] &gt; 1) &amp; (df['payout'] &lt;= 2), 'postTestScore'].sum()
  etc...
  </code></pre>
  
  <p>Well it works, but does anyone know a more succinct (pythonic) solution of this one?</p>