title: in a few conditions, compare row with a previous row and drop rows with condition in python pandas
body: <p>I have a concept of what I need to do, but I can't write the right code to run, please take a look and give some advice.</p>
  <p>step 1. find the rows that contains values in the second column</p>
  <p>step 2. with those rows, compare the value in the first column with their previous row</p>
  <p>step 3. drop the rows with larger first column value</p>
  <pre><code>|missing | diff |
  |--------|------|
  | 0      | nan  |
  | 1      | 60   |
  | 1      | nan  |
  | 0      | nan  |
  | 0      | nan  |
  | 1      | 180  |
  | 1      | nan  |
  | 0      | 120  |
  </code></pre>
  <p>eg. I want to compare the missing values with the rows values in diff [120,180,60] and their previous rows. in the end, the desire dataframe will look like</p>
  <pre><code>|missing | diff |
  |--------|------|
  | 0      | nan  |
  | 1      | nan  |
  | 0      | nan  |
  | 0      | nan  |
  | 0      | 120  |
  </code></pre>
  <p>update question according to the answer, got the same df as original df</p>
  <pre><code>import pandas as pd
  import numpy as np
  data={'missing':[0,1,1,0,0,1,1,0],'diff':[np.nan,60,np.nan,np.nan,np.nan,180,np.nan,120]}
  df=pd.DataFrame(data)
  df
  </code></pre>
  <pre><code>missing diff
  0   0   NaN
  1   1   60.0
  2   1   NaN
  3   0   NaN
  4   0   NaN
  5   1   180.0
  6   1   NaN
  7   0   120.0
  </code></pre>
  <pre><code>if df['diff'][ind]!=np.nan:
      if ind!=0:
          if df['missing'][ind]&gt;df['missing'][ind-1]:
              df=df.drop(ind,0)
          else:
              df=df.drop(ind-1,0)
  df
  </code></pre>
  <pre><code>missing diff
  0   0   NaN
  1   1   60.0
  2   1   NaN
  3   0   NaN
  4   0   NaN
  5   1   180.0
  6   1   NaN
  7   0   120.0
  </code></pre>