title: create categorical variables by condition in python with pandas or statsmodels
body: <p>I want to create categorical variables from my data with this method:</p>
  
  <pre><code>cat.var  condition
  1          x &gt; 10
  2          x == 10
  3          x &lt; 10
  </code></pre>
  
  <p>I try using <a href="http://statsmodels.sourceforge.net/devel/contrasts.htm" rel="nofollow">C() method</a> from <code>patsy</code> , but it doesn't work, I know in stata I have to use code below, but after searching I didn't find any clean way to do this in <code>pyhton</code>:</p>
  
  <pre><code>generate mpg3    = .   
  
   (74 missing values generated) 
  
  replace  mpg3    = 1 if (mpg &lt;= 18) 
  
   (27 real changes made) 
  
  replace  mpg3    = 2 if (mpg &gt;= 19) &amp; (mpg &lt;=23) 
  
   (24 real changes made) 
  
  replace  mpg3    = 3 if (mpg &gt;= 24) &amp; (mpg &lt;.) 
  
   (23 real changes made
  </code></pre>