title: pandas merge dataframes by closest time
body: <p>I've got two dataframes (<code>logs</code> and <code>failures</code>), which I would like to merge so that I add in <code>logs</code> a column which has the value of the closest date found in 'failures'.</p>
  
  <p>The code to generate <code>logs</code>, <code>failures</code>, and the desired <code>output</code> is below:</p>
  
  <pre><code>import pandas as pd
  logs=pd.DataFrame({'date-time':pd.Series(['23/10/2015 10:20:54','22/10/2015 09:51:32','21/10/2015 06:51:32','28/10/2015 16:59:32','25/10/2015 04:41:32','24/10/2015 11:50:11']),'var1':pd.Series([0,1,3,1,2,4])})
  logs['date-time']=pd.to_datetime(logs['date-time'])
  failures=pd.DataFrame({'date':pd.Series(['23/10/2015 00:00:00','22/10/2015 00:00:00','21/10/2015 00:00:00']),'failure':pd.Series([1,1,1])})
  failures['date']=pd.to_datetime(failures['date'])
  output=pd.DataFrame({'date-time':pd.Series(['23/10/2015 10:20:54','22/10/2015 09:51:32','21/10/2015 06:51:32','28/10/2015 16:59:32','25/10/2015 04:41:32','24/10/2015 11:50:11']),'var1':pd.Series([0,1,3,1,2,4]),'closest_failure':pd.Series(['23/10/2015 00:00:00','22/10/2015 00:00:00','21/10/2015 00:00:00','23/10/2015 00:00:00','23/10/2015 00:00:00','23/10/2015 00:00:00'])})
  output['date-time']=pd.to_datetime(output['date-time'])
  </code></pre>
  
  <p>Any ideas? The real dataset is very large, so efficiency is also a concern.</p>