title: Create a feature in pandas based on another column
body: <p>I have the following dataset:</p>
  
  <pre><code>data = {'ROC_9':  [0.006250, 0.087230, 0.045028, 0.165738, -0.006993, -0.432736, -0.11162, 0.057466, 0.203138, -0.008234]}
  
  price_data = pd.DataFrame (data)
  </code></pre>
  
  <p>It is an indicator about a stock price, namely rate of change.</p>
  
  <p>I want to write a code that creates a new feature (column) on the pandas data frame when a current feature on the pandas data frame goes from positive to negative, or vice versa.</p>
  
  <p>It is easier explained through an example: lets use the feature <code>ROC9</code>.</p>
  
  <p>I create a new variable called <code>ROC9_signal</code> and set it equal to <code>0</code>:</p>
  
  <pre><code>`price_data['ROC9_signal'] = 0`
  </code></pre>
  
  <p>When <code>ROC_9</code> goes from <code>negative</code> to <code>positive</code>, I want to change the <code>ROC9_signal</code> from <code>0</code> to <code>1</code>.</p>
  
  <p>When <code>ROC_9</code> goes from <code>positive</code> to <code>negative</code>, I want to change the <code>ROC9_signal</code> from <code>0</code> to <code>-1</code>.</p>
  
  <p>Looking at the data, I would like <code>ROC9_signal</code> to change from <code>0</code> to <code>-1</code>, since the value has gone from <code>0.16</code> (<code>positive</code>) to <code>-0.006</code> (<code>negative</code>). </p>
  
  <p>Looking at the data, I would like <code>ROC_9</code> signal to change from <code>0</code> to <code>1</code>, since the value has gone from -<code>0.11</code> (<code>negative</code>) to <code>0.05</code> (<code>positive</code>).</p>
  
  <p>Looking at the data, I would like <code>ROC9_signal</code> to change from <code>0</code> to <code>-1</code>, since the value has gone from <code>0.20</code> (positive) to -<code>0.008</code> (<code>negative</code>). </p>
  
  <p>It is only the row where the change happens that I want to change from 0 to 1 or 0 to -1, the other rows must remain at 0. </p>
  
  <p>I will then apply this same logic to create a <code>momentum10_signal</code> column and a <code>chalkin_money_flow_signal</code> column. Therefore I want a solution that can be applied to different columns and not manually.</p>
  
  <p>Thanks in advance for the help.</p>
  
  <p>This is what the full data looks like:</p>
  
  <p><a href="https://i.stack.imgur.com/3labS.png" rel="nofollow noreferrer">Full Data</a></p>