title: lambda function to compare two consecutive rows in a dataframe and create a new column
body: <p>I have a dataframe  <code>df['y0', 'size]</code> as two columns in it.  </p>
  
  <p>y0 has float values from 25.0 to 800.0<br>
  size is a float datatype, which has values from 8 to 25.  </p>
  
  <pre><code>import pandas as pd
  
  data = '''\
  y0    Size
  25    8  
  37    8.7  
  68.5  9.3  
  93.4  11.4  
  110.7  14.6  
  145.6  12.1  
  180.3  10.9'''
  
  df = pd.read_csv(pd.compat.StringIO(data), sep='\s+')
  </code></pre>
  
  <p>and so on...  </p>
  
  <p><strong>Desired output</strong><br>
  create a new column [y0Dash], which has this logic:  </p>
  
  <pre><code>MIN_Y0_DIFF = 0.3
  
  if ((df['y0'] - df[['y0'].shift(-1)]) /
             ((df['Size'] + df[['Size'].shift(-1)]) / 2) &lt; MIN_Y0_DIFF) ):
      df['y0Dash'] = df['y0']
  else:
      df['y0Dash'] = df['y0'].shift(-1)
  </code></pre>
  
  <p>I get the error that I am trying to compare a scalar value with a series, which I understand - I am trying to compare with MIN_Y0_DIFF.</p>
  
  <p>But, I am not getting how to do this in a lambda function. How compare two consecutive rows to get my desired result?</p>
  
  <p><strong>What I tried</strong>  </p>
  
  <pre><code>def columnCompare():  
      if ((df['y0'] - df[['y0'].shift(-1)]) /
                 ((df['Size'] + df[['Size'].shift(-1)]) / 2) &lt; MIN_Y0_DIFF) ):
          df['y0Dash'] = df['y0']
      else:
          df['y0Dash'] = df['y0'].shift(-1)
  
  
  df = df.apply(lambda x: columnCompare)
  </code></pre>