title: vectorize conditional assignment in pandas dataframe
body: <p>If I have a dataframe <code>df</code> with column <code>x</code> and want to create column <code>y</code> based on values of <code>x</code> using this in pseudo code:</p>
  <pre><code>if df['x'] &lt; -2 then df['y'] = 1 
  else if df['x'] &gt; 2 then df['y'] = -1 
  else df['y'] = 0
  </code></pre>
  <p>How would I achieve this?  I assume <code>np.where</code> is the best way to do this but not sure how to code it correctly.</p>