I have a pandas dataframe as below:
| id | location | timestamp |
|---|---|---|
| 001 | A | 2022-01-01 17:00:00 |
| 001 | B | 2022-01-01 18:00:00 |
| 001 | B | 2022-01-01 18:15:00 |
| 002 | B | 2022-01-01 18:30:00 |
| 003 | B | 2022-01-01 19:00:00 |
| 003 | A | 2022-01-01 20:00:00 |
I'd like to filter records where location is B and only after the same id has visited location A (i.e. the timestamp of B is later than the timestamp of A). Desired output as below:
| id | location | timestamp |
|---|---|---|
| 001 | B | 2022-01-01 18:00:00 |
| 001 | B | 2022-01-01 18:15:00 |
Thank you for your help!