This question builds on the one asked here: How to join two dataframes for which column values are within a certain range? and answered by @coldspeed . Below is the DataFrame modified for my problem:
print df_1
timestamp A B User
0 2016-05-14 10:00 0.020228 0.026572 1
1 2016-05-14 10:00 0.057780 0.175499 2
2 2016-05-14 10:00 0.098808 0.620986 3
3 2016-05-14 10:15 0.158789 1.014819 1
4 2016-05-14 10:15 0.038129 2.384590 2
5 2016-05-14 10:15 0.038129 2.384590 3
print df_2
start end event User
0 2016-05-14 10:00 2016-05-14 10:54:33 E1 1
1 2016-05-14 10:00 2016-05-14 10:54:37 E2 2
2 2016-05-14 10:00 2016-05-14 10:54:42 E3 3
desired output:
timestamp A B User event
0 2016-05-14 10:00 0.020228 0.026572 1 E1
1 2016-05-14 10:00 0.057780 0.175499 2 E2
2 2016-05-14 10:00 0.098808 0.620986 3 E3
3 2016-05-14 10:15 0.158789 1.014819 1 E1
4 2016-05-14 10:15 0.038129 2.384590 2 E2
5 2016-05-14 10:15 0.038129 2.384590 3 E3
So, I believe I can use as a base:
idx = pd.IntervalIndex.from_arrays(df_2['start'], df_2['end'], closed='both')
event = df_2.loc[idx.get_indexer(df_1.timestamp), 'event']
df_1['event'] = event.values
But I need a way to reference the UserID to prevent mixing up the sessions that overlap.