title: Element-wise Maximum of Two DataFrames Ignoring NaNs
body: <p>I have two dataframes (df1 and df2) that each have the same rows and columns.  I would like to take the maximum of these two dataframes, element-by-element.  In addition, the result of any element-wise maximum with a number and NaN should be the number.  The approach I have implemented so far seems inefficient:</p>
  
  <pre><code>def element_max(df1,df2):
      import pandas as pd
      cond = df1 &gt;= df2
      res = pd.DataFrame(index=df1.index, columns=df1.columns)
      res[(df1==df1)&amp;(df2==df2)&amp;(cond)]  = df1[(df1==df1)&amp;(df2==df2)&amp;(cond)]
      res[(df1==df1)&amp;(df2==df2)&amp;(~cond)] = df2[(df1==df1)&amp;(df2==df2)&amp;(~cond)]
      res[(df1==df1)&amp;(df2!=df2)&amp;(~cond)] = df1[(df1==df1)&amp;(df2!=df2)]
      res[(df1!=df1)&amp;(df2==df2)&amp;(~cond)] = df2[(df1!=df1)&amp;(df2==df2)]
      return res
  </code></pre>
  
  <p>Any other ideas?  Thank you for your time.</p>