title: Grouping / Categorizing ages column
body: <p>I have a dataframe say <code>df</code>. <code>df</code> has a column <code>'Ages'</code></p>
  
  <p><code>&gt;&gt;&gt; df['Age']</code></p>
  
  <p><a href="https://i.stack.imgur.com/pcs2l.png" rel="noreferrer"><img src="https://i.stack.imgur.com/pcs2l.png" alt="Age Data"></a></p>
  
  <p>I want to group this ages and create a new column something like this</p>
  
  <pre><code>If age &gt;= 0 &amp; age &lt; 2 then AgeGroup = Infant
  If age &gt;= 2 &amp; age &lt; 4 then AgeGroup = Toddler
  If age &gt;= 4 &amp; age &lt; 13 then AgeGroup = Kid
  If age &gt;= 13 &amp; age &lt; 20 then AgeGroup = Teen
  and so on .....
  </code></pre>
  
  <p>How can I achieve this using Pandas library.</p>
  
  <p>I tried doing this something like this</p>
  
  <pre><code>X_train_data['AgeGroup'][ X_train_data.Age &lt; 13 ] = 'Kid'
  X_train_data['AgeGroup'][ X_train_data.Age &lt; 3 ] = 'Toddler'
  X_train_data['AgeGroup'][ X_train_data.Age &lt; 1 ] = 'Infant'
  </code></pre>
  
  <p>but doing this i get this warning </p>
  
  <blockquote>
    <p>/Users/Anand/miniconda3/envs/learn/lib/python3.7/site-packages/ipykernel_launcher.py:3: SettingWithCopyWarning: 
    A value is trying to be set on a copy of a slice from a DataFrame
    See the caveats in the documentation: <a href="http://pandas.pydata.org/pandas-docs/stable/indexing.html#indexing-view-versus-copy" rel="noreferrer">http://pandas.pydata.org/pandas-docs/stable/indexing.html#indexing-view-versus-copy</a>
      This is separate from the ipykernel package so we can avoid doing imports until
    /Users/Anand/miniconda3/envs/learn/lib/python3.7/site-packages/ipykernel_launcher.py:4: SettingWithCopyWarning: 
    A value is trying to be set on a copy of a slice from a DataFrame</p>
  </blockquote>
  
  <p>How to avoid this warning and do it in a better way.</p>