title: Nearest neighbor matching in Pandas
body: <p>Given two DataFrames (t1, t2), both with a column 'x', how would I append a column to t1 with the ID of t2 whose 'x' value is the nearest to the 'x' value in t1?</p>
  
  <pre><code>t1:
  id  x
  1   1.49
  2   2.35
  
  t2:
  id  x
  3   2.36
  4   1.5
  
  output:
  id  id2
  1   4
  2   3
  </code></pre>
  
  <p>I can do this by creating a new DataFrame and iterating on t1.groupby() and doing look ups on t2 then merging, but this take incredibly long given a 17 million row t1 DataFrame.</p>
  
  <p>Is there a better way to accomplish? I've scoured the pandas docs regarding groupby, apply, transform, agg, etc. But an elegant solution has yet to present itself despite my thought that this would be a common problem.</p>