title: Pandas apply formula to each row and find minimum
body: <p>I'm looking for an efficient way to apply a formula using variables from a single row of one dataframe (df1) against every row in another datframe (df2), then find the minimum value of this operation and store the row from df2 in which this minimum value occured as a new dataframe (df3).
  example input/output is given.</p>
  <pre><code>df1                
  Index   X1  Y1  Z1      
  1       3   6   4        
  2       7   2   1       
  3       4   7   3       
  
  df2
  Index   X2  Y2  Z2
  1       2   4   1
  2       5   3   2
  3       7   1   5
  </code></pre>
  <p>Formuala to apply:</p>
  <pre><code>d = math.sqrt((X2-X1)**2 + (Y2-Y1)**2 + (Z2-Z1)**2)
  </code></pre>
  <p>If this formula was to be applied iteratively to df2, where (X1, Y1, Z1) is from df1 row1 and (X2, Y2, Z2) are taken from each row in df2 to give.</p>
  <pre><code>[out]
  Index  d
  1      3.741
  2      4.123
  3      6.481
  </code></pre>
  <p>Since (X2, Y2, Z2) in df2 row 1 provided the lowest d value, this row would be saved into df3 and the process then repeated for each row in df1.</p>
  <pre><code>df3
  Index  X2  Y2  Z2  
  1      2   4   1 
  </code></pre>
  <p>*Note, df1 and df2 are of different length. Apologies if this question seems long-winded, I'm just trying to be as clear as possible.</p>