title: Using pd.apply() with shift to compare adjacent rows
body: <p>I'd like to compare adjacent rows on two separate columns. I have a <code>dataframe</code> with two columns, <code>Letter</code> and <code>Boolean_Value</code>. I would like to create a new column, <code>New Col</code> in which the value is <code>True</code> or <code>False</code>. </p>
  
  <p>For the value to be true: </p>
  
  <p>The next row down (higher index) must share the same <code>Letter</code> value and the the next row down must have a <code>Boolean_Value</code> of True.</p>
  
  <p>for the value to be false:</p>
  
  <p>All other scenarios </p>
  
  <p>My code, yields all false values:</p>
  
  <pre><code>import pandas as pd
  df = pd.DataFrame(data=[['A', False],
                          ['A', True],
                          ['B', False],
                          ['B', False],
                          ['B', True]]
                    ,columns=['Letter', 'Boolean_Value'])
  
  def my_test2(row):
      try:
          if row['Letter'].shift(1) == row['Letter'] and row['Boolean_Value'].shift(1) == True:
              return True
          else:
              return False
      except:
          return False
  
  df['New Col'] = df.apply(my_test2, axis=1)
  
  print df
  </code></pre>
  
  <p>Yields:</p>
  
  <pre><code>  Letter Boolean_Value New Col
  0      A         False   False
  1      A          True   False
  2      B         False   False
  3      B         False   False
  4      B          True   False
  </code></pre>
  
  <p>Desired output:</p>
  
  <pre><code>  Letter Boolean_Value New Col
  0      A         False   True
  1      A          True   False
  2      B         False   False
  3      B         False   True
  4      B          True   False
  </code></pre>