This is followup question of this
I have two dataframes
:
print df_1
timestamp A B
0 2016-05-15 0.020228 0.026572
1 2016-05-15 0.057780 0.175499
2 2016-05-15 0.098808 0.620986
3 2016-05-17 0.158789 1.014819
4 2016-05-17 0.038129 2.384590
5 2018-05-17 0.011111 9.999999
print df_2
start end event
0 2016-05-14 2016-05-16 E1
1 2016-05-14 2016-05-16 E2
2 2016-05-17 2016-05-18 E3
I would like to merge df_1
and df_2
and get the event column
in df_1
if the timestamp
falls in between of start
and end
.
The problems, and the differences with this question, are
1) that event
s E1
and E2
have the same start
and end
.
2) Also in df_1
the 6th row does not fall inside any of the intervals.
In the end I would like to have both of the events and for the row that does not have any event have NA
.
So I would like my resulting dataframe
to be like this
timestamp A B event
0 2016-05-15 0.020228 0.026572 E1
1 2016-05-15 0.057780 0.175499 E1
2 2016-05-15 0.098808 0.620986 E1
3 2016-05-15 0.020228 0.026572 E2
4 2016-05-15 0.057780 0.175499 E2
5 2016-05-15 0.098808 0.620986 E2
6 2016-05-17 0.158789 1.014819 E3
7 2016-05-17 0.038129 2.384590 E3
8 2018-05-17 0.011111 9.999999 NA