I have 2 datasets as follows:
dataset1 = [['05/06/2017 12:05:27', data1, data1],
['12/05/2017 12:30:27', data1, data1],
.... ....
]
dataset2 = [['06/02/2017 13:39:11', data2, data2],
['10/10/2016 11:26:40', data2, data2],
.... ....
]
I am trying to create a condition where if the datetime in dataset1 is within 6 hours of the datetime in dataset2, add the data in dataset1 to the corresponding row in dataset2.
I have converted the datetime elements from str to datetime objects. And I think I need to use the timedelta function to see if the difference between the dates is less than 6 hours but the lists are not of equal size nor are the dates necessarily sequential so I'm not sure how to go about comparing the lists and finding a match.
What I've done so far is separate the datetime elements into new lists... pseudocode:
DatetimeDataset1 = [...]
DatetimeDataset2 = [...]
for i in DatetimeDataset1:
for j in DatetimeDataset2:
if i - j < 6 hours:
do something!
How do I specify 6 hours in this condition in a way the objects would understand?
Need some direction.
Thanks