I've spent a few hours on google searching to solve this problem, but I haven't been able to find anything regarding these parameters. I want to find if a value associated with a specific datetime occurs between at least one datetime range in another data frame of a different size. Below are the example data frames:
import pandas as pd
df1 = pd.DataFrame({'Datetime': ['2020-01-01 01:01:01', '2020-01-01 10:10:10', '2020-01-01 12:10:01', '2020-01-02 03:16:24', '2020-12-01 04:34:21'], 'Value': [0.006, 0.002, 0.005, 0.034, 0.001]})
df2 = pd.DataFrame({'Start': ['2020-01-01 01:01:00', '2020-01-01 07:10:10', '2020-01-01 21:10:01', '2020-01-03 06:16:24', '2020-12-25 14:12:34'], 'End': ['2020-01-01 02:00:00', '2020-01-01 08:01:01', '2020-01-01 21:34:09', '2020-01-01 09:23:42', '2020-12-25 15:13:21']})
# convert columns to datetime format
df1.Datetime = pd.to_datetime(df1.Datetime)
df2[['Start', 'End']] = df2[['Start', 'End']].apply(pd.to_datetime)
df1
Datetime Value Check
2020-01-01 01:01:01 0.006
2020-01-01 10:10:10 0.002
2020-01-01 12:10:01 0.005
2020-01-02 03:16:24 0.034
2020-12-01 04:34:21 0.001
df2
Start End
2020-01-01 01:01:00 2020-01-01 02:00:00
2020-01-01 07:10:10 2020-01-01 08:01:01
2020-01-01 21:10:01 2020-01-01 21:34:09
2020-01-03 06:16:24 2020-01-01 09:23:42
2020-12-25 14:12:34 2020-12-25 15:13:21
If df1['Value'] associated with df1['Datetime'] at index 1 is between any of the ranges in df2, the function should return True in df1['Check'] and False if the associated datetime is not between any of the ranges. This should continue to check every index in df1 against all ranges in df2.
I've tried using pd.DataFrame.any, but this throws "ValueError: Can only compare identically-labeled Series objects". I was thinking a nested for loop would be the way to go, but I am not sure how to set one up for something like this.