I want to slice rows in df1 in between time intervals StartTime and EndTime in df2 on a case by case basis(by values in column Group_Id in df2). Then concatenate the multiple slices together given they are of the same formats.
So this is df1:
Timestamp Group_Id Data
2013-10-20 00:00:05.143 11 14
2013-10-21 00:05:10.377 11 15
2013-10-22 14:22:15.501 11 19
...
2019-02-05 00:00:05.743 101 21
2019-02-10 00:00:10.407 101 33
and df2:
EndTime StartTime Group_Id
27/10/13 16:08 20/10/13 16:08 11
03/12/16 16:11 26/11/16 16:11 2
24/10/14 12:08 17/10/14 12:08 11
04/07/17 08:00 27/06/17 08:00 100
03/04/13 14:10 27/03/13 14:10 26
15/11/18 17:00 08/11/18 17:00 46
11/02/19 00:20 04/02/19 00:20 101
Step1:
We start from first row in column Group_Id,df2: 11
Step2:
Copy & Paste corresponding rows in df1 that lie between EndTime & StartTime for Group_Id==11
Step3:
Concat all sliced subsets from each row in Group_Id(df2)
Hopefully final dataset df3 looks like this:
Group_Id EndTime StartTime Timestamp Data
11 27/10/13 16:08 20/10/13 16:08 2013-10-20 20:00:05.143 14
11 27/10/13 16:08 20/10/13 16:08 2013-10-21 00:05:10.377 15
11 27/10/13 16:08 20/10/13 16:08 2013-10-22 14:22:15.501 19
...
101 11/02/19 00:20 04/02/19 00:20 2019-02-05 00:00:05.743 21
101 11/02/19 00:20 04/02/19 00:20 2019-02-10 00:00:10.407 33
...
A bad Pseudo code:
for i in df2['Group_Id']:
if i = df1['Group_Id'],
dfxx = df1[(df1['Timestamp'] <= df2.loc[i, 'EndTime']) & df1['Timestamp'] > (df2.loc['EndTime'] - dt.timedelta(days=7)])
pd.concat(dfxx for all i)
i = i+1
Hope this helps to better illustrate the problem.
df1.Timestamp2013-10-20 00:00:05.143is outside of27/10/13 16:08 20/10/13 16:08. Why is it in the output?