I want to write a code where it compares dates and selected_dates and states the intervals selected_dates occupies within dates and does not occupy. So it looks for consecutive number of times dates are in both dates and selected_dates have been in each other and records the timestamp of the start and end. The inverse as well so the consecutive number of times they have not been in each other seen in the Non Occupying dates. So we can see that the values [2021-08-15 07:49:00', '2021-08-15 07:49:02', '2021-08-15 07:51:15', '2021-08-15 07:51:34'] are in both arrays so the initial and end would be shown as 2021-08-15 07:49:02 - 2021-08-15 07:51:34 in the Occupying dates. How would I be able to do such a thing and get the Expected Output?
from datetime import datetime
import numpy as np
import pandas as pd
dates = ['2021-08-15 03:16:34', '2021-08-15 03:17:24', '2021-08-15 03:20:02', '2021-08-15 05:56:17', '2021-08-15 05:57:01', '2021-08-15 07:49:00', '2021-08-15 07:49:02', '2021-08-15 07:51:15', '2021-08-15 07:51:34', '2021-08-15 08:33:39']
selected_dates= ['2021-08-15 03:16:34', '2021-08-15 03:17:24', '2021-08-15 07:49:02', '2021-08-15 07:51:15', '2021-08-15 07:51:34']
Expected Output
Occupying dates:
2021-08-15 03:16:34 - 2021-08-15 03:17:24
2021-08-15 07:49:02 - 2021-08-15 07:51:34
Non Occupying dates:
2021-08-15 03:20:02 - 2021-08-15 05:57:01
2021-08-15 08:33:39