I have the following dataframe
Station | Sub station | Start Date | End Date |
---|---|---|---|
Alpha | X | 1/11/2023 | 8/31/2023 |
Alpha | X | 9/11/2023 | 10/31/2023 |
Alpha | Y | 11/10/2023 | 12/31/2023 |
Beta | Z | 1/10/2023 | 2/10/2023 |
Beta | Z | 2/11/2023 | 3/10/2023 |
Beta | Z | 9/1/2023 | 10/1/2023 |
For a given Station and sub station pair I would like to get the number of days between the start date and the previous end date grouped by the station and sub station.
Ideal result would be:
Station | Sub station | Start Date | End Date | Diff From Prev |
---|---|---|---|---|
Alpha | X | 1/11/2023 | 8/31/2023 | NaN |
Alpha | X | 9/11/2023 | 10/31/2023 | 11 |
Alpha | Y | 11/10/2023 | 12/31/2023 | NaN |
Beta | Z | 1/10/2023 | 2/10/2023 | NaN |
Beta | Z | 2/11/2023 | 3/10/2023 | 1 |
Beta | Z | 9/1/2023 | 10/1/2023 | 175 |
I am not sure how to do this. Any guidance is appreciated! Thank you.