title: potential solutions to create categories in pandas
body: <p>I was wondering if there are better solutions to create a categorical variable based on specified ranges of a numeric column in Pandas.</p>
  <p>I have tried using a function or <code>np.where</code>.</p>
  <pre><code>import pandas as pd
  
  df = pd.DataFrame({'n': [1, 2, 3, 4, 5, 6, 7, 8] }) 
  
  def create_cat(x):
   
      if x &lt; 3:
         return &quot;Low&quot;
      elif x &gt; 3 and x &lt; 6:
         return &quot;Med&quot;
      elif x &gt; 6:
         return &quot;High&quot;
  
  df[col] = df[col].apply(lambda x: create_cat(x), axis=1)
  </code></pre>
  <p>Are there other approaches that might be better than writing a function?</p>