title: Pandas: If statement with multiple conditions on pandas dataframe
body: <p>I am trying to compare rows within a group and if a condition is met within the rows, I want to either keep the complete group, keep the most recent row, or keep the first row. </p>
  
  <p>The dataframe will only have 2 items per group. If the first row of the group has the LastFour digits of '2290' OR if it start with the letter 'M' AND if in the second row the LastFour column is equal to either 0087 OR 0117 AND if NUM != 6708 then I want to keep both rows. This is the first conditional. The second condition is if the rows are the same for each column except for the Date column then keep the row with the most recent date. Else, if neither of these conditions are met, keep the first row only and remove the second row.</p>
  
  <p>Original df:</p>
  
  <pre><code>    KEY     CLAIM       LastFour    NUM     Date1       Date2     Code  
  166 0944    163         0087        30087   3/2/2012    3/5/2012    1   
  167 0944    164         0087        30087   3/3/2012    3/5/2012    1   
  225 1413    222         2290        123422  2/10/2012   2/11/2012   1   
  226 1413    223         0032        123123  2/10/2012   2/11/2012   1   
  315 1979    312         0025        70025   12/24/2011  1/6/2012    3   
  316 1979    313         0025        70025   12/24/2011  1/6/2012    3   
  320 1997    317         0007        140007  1/1/2012    1/4/2012    2   
  321 1997    318         0007        140007  1/1/2012    1/4/2012    2   
  </code></pre>
  
  <p>Anticipated result:</p>
  
  <pre><code>    KEY     CLAIM       LastFour    NUM     Date1       Date2     Code  Keep
  166 0944    163         0087        30087   3/2/2012    3/5/2012    1   FALSE
  167 0944    164         0087        30087   3/3/2012    3/5/2012    1   TRUE
  225 1413    222         2290        123422  2/10/2012   2/11/2012   1   TRUE
  226 1413    223         0032        123123  2/10/2012   2/11/2012   1   TRUE
  315 1979    312         0025        70025   12/24/2011  1/6/2012    3   FALSE
  316 1979    313         0025        70025   12/24/2011  1/6/2012    3   TRUE
  320 1997    317         0007        140007  1/1/2012    1/4/2012    2   FALSE
  321 1997    318         0007        140007  1/1/2012    1/4/2012    2   TRUE
  </code></pre>
  
  <p>My approach was to use an if statement but I'm having trouble.</p>
  
  <pre><code>if ((df['KEY'] == df['KEY'].shift(-1)) &amp; (df['LastFour'].isin(['2290'])) \
              | (df['LastFour'].str.get(0).isin(['M']))) &amp; \
  ((df['KEY'] == df['KEY'].shift(-1)) &amp; (df['LastFour'].isin(['0087','0117'])) | (~df['NUM'].isin(['670899']))):
      pass
  if (df['KEY'] == df['KEY'].shift(-1)) &amp; (df['LastFour'] == df['LastFour'].shift(-1)) &amp; (df['NUM'] == df['NUM'].shift(-1)):
      df.groupby('KEY').Date.transform('last')
  else:
      df.groupby('Key').iloc[0]
  </code></pre>
  
  <p>I appreciate any help.</p>