title: Vlookup in Python with approximate match in a large dataframe
body: <p>I have the following problem.</p>
  <p>I have the base dataframe (df):</p>
  <div class="s-table-container">
  <table class="s-table">
  <thead>
  <tr>
  <th>Type</th>
  <th>Bid</th>
  <th>Ask</th>
  <th>Hora</th>
  <th>Data</th>
  <th>Two Seconds</th>
  </tr>
  </thead>
  <tbody>
  <tr>
  <td>Buyer</td>
  <td>5711.0</td>
  <td>5711.5</td>
  <td>09:00:49</td>
  <td>2022-01-07</td>
  <td>09:00:51</td>
  </tr>
  <tr>
  <td>Seller</td>
  <td>5710.0</td>
  <td>5710.5</td>
  <td>09:00:52</td>
  <td>2022-01-07</td>
  <td>09:00:54</td>
  </tr>
  <tr>
  <td>Buyer</td>
  <td>5707.5</td>
  <td>5708.0</td>
  <td>09:00:53</td>
  <td>2022-01-07</td>
  <td>09:00:55</td>
  </tr>
  <tr>
  <td>Buyer</td>
  <td>5700.5</td>
  <td>5701.0</td>
  <td>17:59:59</td>
  <td>2022-01-14</td>
  <td>18:00:01</td>
  </tr>
  </tbody>
  </table>
  </div>
  <p>And I have the dataframe with prices (prices):</p>
  <div class="s-table-container">
  <table class="s-table">
  <thead>
  <tr>
  <th>Bid</th>
  <th>Ask</th>
  <th>Hora</th>
  <th>Data</th>
  </tr>
  </thead>
  <tbody>
  <tr>
  <td>5713.0</td>
  <td>5713.5</td>
  <td>09:00:51</td>
  <td>2022-01-07</td>
  </tr>
  <tr>
  <td>5708.0</td>
  <td>5708.5</td>
  <td>09:00:55</td>
  <td>2022-01-07</td>
  </tr>
  <tr>
  <td>5703.5</td>
  <td>5704.0</td>
  <td>18:00:00</td>
  <td>2022-01-14</td>
  </tr>
  </tbody>
  </table>
  </div>
  <p>I would like to do vlookup column Two Seconds in df prices with approximate match. The expected result would be:</p>
  <div class="s-table-container">
  <table class="s-table">
  <thead>
  <tr>
  <th>Type</th>
  <th>Bid</th>
  <th>Ask</th>
  <th>Hora</th>
  <th>Data</th>
  <th>Two Seconds</th>
  </tr>
  </thead>
  <tbody>
  <tr>
  <td>Buyer</td>
  <td>5711.0</td>
  <td>5711.5</td>
  <td>09:00:49</td>
  <td>2022-01-07</td>
  <td>5713.5</td>
  </tr>
  <tr>
  <td>Seller</td>
  <td>5710.0</td>
  <td>5710.5</td>
  <td>09:00:52</td>
  <td>2022-01-07</td>
  <td>5713.0</td>
  </tr>
  <tr>
  <td>Buyer</td>
  <td>5707.5</td>
  <td>5708.0</td>
  <td>09:00:53</td>
  <td>2022-01-07</td>
  <td>5708.5</td>
  </tr>
  <tr>
  <td>Buyer</td>
  <td>5700.5</td>
  <td>5701.0</td>
  <td>17:59:59</td>
  <td>2022-01-14</td>
  <td>5704.0</td>
  </tr>
  </tbody>
  </table>
  </div>
  <p>I have tried the following, but I could not approximate match and my two dataframes are very large, so this code is very slow:</p>
  <p><code>df[&quot;Two_seconds&quot;] = df.apply(lambda x: prices.loc[(prices[&quot;Data&quot;] == x[&quot;Data&quot;]) &amp; (prices[&quot;Hora&quot;] == x[&quot;Two_seconds&quot;]),'Bid' if x[&quot;Tipo&quot;] == &quot;Buyer&quot; else 'Ask'], axis = 1)</code></p>
  <p>How I can solve this problem?</p>
  <p>thx</p>