title: Trying to create grouped variable in python
body: <p>I have a column of age values that I need to convert to age ranges of 18-29, 30-39, 40-49, 50-59, 60-69, and 70+:</p>
  
  <p>For an example of some of the data in df 'file', I have:</p>
  
  <p><a href="https://i.stack.imgur.com/nmcUh.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/nmcUh.png" alt="enter image description here"></a></p>
  
  <p>and would like to get to:</p>
  
  <p><a href="https://i.stack.imgur.com/lLuAG.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/lLuAG.png" alt="enter image description here"></a></p>
  
  <p>I tried the following:</p>
  
  <pre><code>file['agerange'] = file[['age']].apply(lambda x: "18-29" if (x[0] &gt; 16
                                         or x[0] &lt; 30) else "other")
  </code></pre>
  
  <p>I would prefer not to just do a groupby since the bucket sizes aren't uniform but I'd be open to that as a solution if it works.</p>
  
  <p>Thanks in advance!</p>