title: Pandas - How to compare two consecutive row of a column
body: <p>I want to find percentage difference of two consecutive rows of a column and if the difference is greater than 10 percent I want to return the first value.
  For example, In the below data, I want to find percentage difference between df.close[0] and df.close[1] and if the difference is greater than 10 then I want to have value of df.close[0] as df.close[1] if the difference is less than 10 then I want to retain the same values for df.close[0] and df.close[1], how to do it=?</p>
  
  <pre><code>           1. open  2. high   3. low  4. close  5. volume
  date                                                      
  2000-01-03  41.7917  42.5000  40.8333   41.2500  2006460.0
  2000-01-04  41.0833  41.0833  38.2500   39.2917  3392856.0
  2000-01-05  37.2083  37.2083  34.0000   34.5500  4344624.0
  2000-01-06  34.5000  36.3333  34.5000   35.6708  2219904.0
  2000-01-07  39.1667  43.2500  38.6667   43.2500  7155936.0
  </code></pre>
  
  <p>I tried the below code, but doesnt seem to work:</p>
  
  <pre><code>def percentage_diff(x):
    if (abs((x[0]-x[1]/x[0])*100)&gt;10):
      return x[0]
    else:
      return x[1]
  
  df.close = pd.rolling_apply(df['close'], 2, percentage_diff)
  </code></pre>