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.

step 1. find the rows that contains values in the second column

step 2. with those rows, compare the value in the first column with their previous row

step 3. drop the rows with larger first column value

```
|missing | diff |
|--------|------|
| 0      | nan  |
| 1      | 60   |
| 1      | nan  |
| 0      | nan  |
| 0      | nan  |
| 1      | 180  |
| 1      | nan  |
| 0      | 120  |

```

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

```
|missing | diff |
|--------|------|
| 0      | nan  |
| 1      | nan  |
| 0      | nan  |
| 0      | nan  |
| 0      | 120  |

```

update question according to the answer, got the same df as original df

```
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

```

```
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

```

```
if df['diff'][ind]!=np.nan:
    if ind!=0:
        if df['missing'][ind]>df['missing'][ind-1]:
            df=df.drop(ind,0)
        else:
            df=df.drop(ind-1,0)
df

```

```
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

```