title: Pandas merge by condition
body: <p>I have two dataframes</p>
  <pre><code>data = {'process': ['buying','selling','searhicng','repairing', 'preparing', 'selling','buying', 'searching', 'selling','searching'],
          'type': ['in_progress','in_progress','end','in_progress', 'end', 'in_progress','in_progress', 'end', 'in_progress','end'],
          'country': ['usa',np.nan, 'usa','ghana', 'ghana','ghana','portugal', 'portugal', 'portugal','england'],
          'id': ['022','022','022', '011','011', '011','011', '011', '011','011'],
          'created': ['2021-07-01','2021-07-03','2021-07-04','2021-07-05','2021-07-09','2021-07-10','2021-07-15','2021-07-17','2021-07-19','2021-07-21']        
  }
  
  df = pd.DataFrame(data, columns = ['process', 'type', 'country', 'id', 'created'])
  df['next_created'] = df.sort_values('created').groupby('id')['created'].shift(-1)
  </code></pre>
  <p><a href="https://i.stack.imgur.com/T8Vn4.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/T8Vn4.png" alt="enter image description here" /></a></p>
  <p>and</p>
  <pre><code>data = {'id': ['022','022','022', '011','011', '011','011', '011', '011','011'],
          'product': ['apple','orange','watermelow', 'qiwi','pear', 'cherry','apple', 'qiwi', 'cherry','orange'],
          'created': ['2021-07-02','2021-07-06','2021-07-07','2021-07-11','2021-07-12','2021-07-13','2021-07-16','2021-07-20','2021-07-25','2021-07-26']        
  }
  df = pd.DataFrame(data, columns = ['product', 'id','created'])
  </code></pre>
  <p><a href="https://i.stack.imgur.com/Ppgph.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/Ppgph.png" alt="enter image description here" /></a></p>
  <p>I need to merge these dataframes by condition:
  in each group by <code>id</code> if <code>df1.created &lt; df2.created &lt; df1.next_created</code></p>
  <p>How can i do it?</p>
  <p>Ouput result:</p>
  <p><a href="https://i.stack.imgur.com/QPc5y.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/QPc5y.png" alt="enter image description here" /></a></p>