title: How to efficiently join two dataframes if they have overlapping intervals?
body: <p>I have two dataframes:</p>
  <pre><code>df_A = pd.DataFrame({'start_date':['2022-07-01 00:02:41','2022-07-01 00:07:41','2022-07-01 00:22:41','2022-07-01 01:01:23','2022-07-01 01:01:23'],'end_date':['2022-07-01 00:02:41','2022-07-01 00:17:41','2022-07-01 00:57:42','2022-07-01 01:01:23','2022-07-01 01:03:51',], 'eventname':['e2','e3','e5','e6','e7',] })
  df_B = pd.DataFrame({'start_date':['2022-07-01 00:00:41','2022-07-01 00:06:41','2022-07-01 00:17:56','2022-07-01 01:03:40',],'end_date':['2022-07-01 00:01:41','2022-07-01 00:14:41','2022-07-01 00:19:42','2022-07-01 02:03:23',], 'eventname':['e1','e3','e4','e7',] })
  
  #df_A
      start_date          end_date            eventname
  0   2022-07-01 00:02:41 2022-07-01 00:02:41 e2
  1   2022-07-01 00:07:41 2022-07-01 00:17:41 e3
  2   2022-07-01 00:22:41 2022-07-01 00:57:42 e5
  3   2022-07-01 01:01:23 2022-07-01 01:01:23 e6
  4   2022-07-01 01:01:23 2022-07-01 01:03:51 e7
  
  
  #df_B
      start_date          end_date            eventname
  0   2022-07-01 00:00:41 2022-07-01 00:01:41 e1
  1   2022-07-01 00:06:41 2022-07-01 00:14:41 e3
  2   2022-07-01 00:17:56 2022-07-01 00:19:42 e4
  3   2022-07-01 01:03:40 2022-07-01 02:03:23 e7
  
  </code></pre>
  <p>I would like to join the rows of df_B to df_A if the time interval has any overlap and my expected result is this:</p>
  <pre><code>df_C = pd.DataFrame({'start_date_A':['nan','2022-07-01 00:02:41','2022-07-01 00:07:41','nan','2022-07-01 00:22:41','2022-07-01 01:01:23','2022-07-01 01:01:23',],'end_date_A':['nan','2022-07-01 00:02:41', '2022-07-01 00:17:41','nan','2022-07-01 00:57:42','2022-07-01 01:01:23','2022-07-01 01:03:51',],'start_date_b':['2022-07-01 00:00:41','nan','2022-07-01 00:06:41','2022-07-01 00:17:56','nan','nan','2022-07-01 01:03:40',],'end_date_b':['2022-07-01 00:01:41', 'nan', '2022-07-01 00:14:41', '2022-07-01 00:19:42', 'nan', 'nan', '2022-07-01 02:03:23', ], 'eventname':['e2','e1','e3','e4','e5','e6','e7']  })
  
  #df_C
  </code></pre>
  <p><a href="https://i.stack.imgur.com/WxPPS.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/WxPPS.png" alt="enter image description here" /></a></p>
  <p>I tried the solution mentioned <a href="https://stackoverflow.com/questions/48168292/merge-two-dataframes-based-on-interval-overlap">here</a> but it gives me only the first value of the column each time, not the value for that row.</p>
  <p>I also tried using the IntervalIndex like this:</p>
  <pre><code>bins = pd.IntervalIndex.from_arrays(df_A['start_date'], 
                                      df_A['end_date'],
                                      closed='both')
  
  out = df_B.assign(interval=pd.cut(df_B['eventname'], bins)) \
            .merge(df_A.assign(interval=bins), on='interval', how='left')
  </code></pre>
  <p>but I get the error that overlapping intervals are not allowed. How can I do this?</p>
  <p><strong>Edit:</strong> eventname also need to be the same for the join to happen. If not, both the rows have to be present separately so it will be a full join</p>