title: Efficient way to get row with closest timestamp to a given datetime in pandas
body: <p>I have a big dataframe that contains around 7,000,000 rows of time series data that looks like this</p>
  
  <pre><code>timestamp               | values 
  2019-08-01 14:53:01     | 20.0
  2019-08-01 14:53:55     | 29.0
  2019-08-01 14:53:58     | 22.4
  ...
  2019-08-02 14:53:25     | 27.9
  </code></pre>
  
  <p>I want to create a column that is a lag version of 1 day for each row, since my timestamps don't match up perfectly, I can't use the normal <code>shift()</code> method.
  The result will be something like this: </p>
  
  <pre><code>timestamp               | values | lag
  2019-08-01 14:53:01     | 20.0   | Nan
  2019-08-01 14:53:55     | 29.0   | Nan
  2019-08-01 14:53:58     | 22.4   | Nan
  ...
  2019-08-02 14:53:25     | 27.9   | 20.0
  </code></pre>
  
  <p>I found some posts related to get the closest timestamp to a given time: <a href="https://stackoverflow.com/questions/15115547/find-closest-row-of-dataframe-to-given-time-in-pandas/19974491">Find closest row of DataFrame to given time in Pandas</a> and tried the methods, it does the job but takes too long to run, here's what I have:</p>
  
  <pre><code>def get_nearest(data, timestamp):
      index = data.index.get_loc(timestamp,"nearest")
      return data.iloc[index, 0]
  df['lag'] = [get_nearest(df, dt) for dt in df.index]
  </code></pre>
  
  <p>Any efficient ways to solve the problem?</p>