title: Python pandas.cut
body: <p>Edit: Added defT</p>
  
  <p>Does using <code>pandas.cut</code> change the structure of a <code>pandas.DataFrame</code>.</p>
  
  <p>I am using <code>pandas.cut</code> in the following manner to map single age years to age groups and then aggregating afterwards. However, the aggregation does not work as I end up with <code>NaN</code> in all columns that are being aggregated. Here is my code:</p>
  
  <pre><code>cutoff = numpy.hstack([numpy.array(defT.MinAge[0]),   defT.MaxAge.values])
  labels = defT.AgeGrp
  
  df['ageGrp'] = pandas.cut(df.Age, 
                            bins              = cutoff, 
                            labels            = labels, 
                            include_lowest    = True)
  </code></pre>
  
  <p>Here is defT:</p>
  
  <pre><code>AgeGrp  MaxAge  MinAge
     1      18      14
     2      21      19
     3      24      22
     4      34      25
     5      44      35
     6      54      45
     7      65      55
  </code></pre>
  
  <p>Then I pass the data-frame into another function to aggregate:</p>
  
  <pre><code>grouped = df.groupby(['Year', 'Month', 'OccID', 'ageGrp', 'Sex', \
                        'Race', 'Hisp', 'Educ'], 
                        as_index = False)
  
  final   = grouped.aggregate(numpy.sum)
  </code></pre>
  
  <p>If I change the ages to age groups via this manner it works perfectly:</p>
  
  <pre><code>df['ageGrp'] = 1
  df.ix[(df.Age &gt;= 14) &amp; (df.Age &lt;= 18), 'ageGrp'] = 1 # Age 16 - 20
  df.ix[(df.Age &gt;= 19) &amp; (df.Age &lt;= 21), 'ageGrp'] = 2 # Age 21 - 25  
  df.ix[(df.Age &gt;= 22) &amp; (df.Age &lt;= 24), 'ageGrp'] = 3 # Age 26 - 44  
  df.ix[(df.Age &gt;= 25) &amp; (df.Age &lt;= 34), 'ageGrp'] = 4 # Age 45 - 64  
  df.ix[(df.Age &gt;= 35) &amp; (df.Age &lt;= 44), 'ageGrp'] = 5 # Age 64 - 85  
  df.ix[(df.Age &gt;= 45) &amp; (df.Age &lt;= 54), 'ageGrp'] = 6 # Age 64 - 85  
  df.ix[(df.Age &gt;= 55) &amp; (df.Age &lt;= 64), 'ageGrp'] = 7 # Age 64 - 85  
  df.ix[df.Age &gt;= 65, 'ageGrp'] = 8 # Age 85+
  </code></pre>
  
  <p>I would prefer to do this on the fly, importing the definition table and using <code>pandas.cut</code>, instead of being hard-coded.</p>
  
  <p>Thank you in advance. </p>