I have a data which has index and date I need to perform logic in which I need to compare the first date with next date if the date range is lesser than 31 remove the second, again compare the first with third if it's greater than 31 keep the first and third and compare the third with fourth if less remove or if greater add keep on like this. Can anyone help me out on this logic

Simply first record should be compared with prior records with greater of 31

```
index     DATE
1     2020-01-01
1     2020-01-15
1     2020-01-30
1     2020-02-02
1     2020-02-20
1     2020-03-05
1     2020-03-25
2     2020-04-30

```

**Required output**

```
index     DATE
1     2020-01-01
1     2020-02-02
1     2020-03-05
2     2020-04-30

```