title: How to apply a function between two pandas data frames
body: <p>How can a custom function be applied to two data frames?  The <a href="https://pandas.pydata.org/pandas-docs/version/0.24.2/reference/api/pandas.DataFrame.apply.html" rel="nofollow noreferrer">.apply method</a> seems to iterate over rows or columns of a given dataframe, but I am not sure how to use this over two data frames at once. For example,</p>
  
  <p>df1</p>
  
  <pre><code>      m1          m2        
         x     y     x     y    z 
  0 0  10.0  12.0  16.0  17.0   9.0
    0  10.0  13.0  15.0  12.0   4.0
  1 0  11.0  14.0  14.0  11.0   5.0
    1   3.0  14.0  12.0  10.0   9.0
  </code></pre>
  
  <p>df2</p>
  
  <pre><code>     m1          m2        
        x     y     x     y    
  0   0.5    0.1    1     0  
  </code></pre>
  
  <p>In general, how can a mapping function of df1 to df2 make a new df3. For example, multiply (but I am looking for a generalized solution where I can just send to a function). </p>
  
  <pre><code>def custFunc(d1,d2):
      return (d1 * d2) - d2
  
  df1.apply(lambda x: custFunc(x,df2[0]),axis=1) 
  #df2[0] meaning it is explicitly first row
  </code></pre>
  
  <p>and a df3 would be </p>
  
  <pre><code>      m1          m2        
         x     y     x     y    z 
  0 0   5.5   1.3  16.0   0.0   9.0
    0   5.5   1.4  15.0   0.0   4.0
  1 0   6.0   1.5  14.0   0.0   5.0
    1   2.0   1.5  12.0   0.0   9.0
  </code></pre>