python pandas-possible to compare 3 dfs of same shape using where(max())? is this a masking issue?
<p>I have a dict containing 3 dataframes of identical shape. I would like to create:</p>

<ol>
<li>a 4th dataframe which identifies the largest value from the original 3 at each coordinate - so dic['four'].ix[0,'A'] = MAX( dic['one'].ix[0,'A'], dic['two'].ix[0,'A'], dic['three'].ix[0,'A'] )</li>
<li><p>a 5th with the second largest value</p>

<pre><code>dic = {}
for i in ['one','two','three']:
    dic[i] = pd.DataFrame(np.random.randint(0,100,size=(10,3)), columns=list('ABC'))
</code></pre></li>
</ol>

<p>I cannot figure out how to use .where() to compare the original 3 dfs. Looping through would be inefficient for ultimate data set. </p>

<p>The 1st question is easy to answer, you could use the <code>numpy.maximum()</code> function to find the element wise maximum value in each cell, across multiple dataframes</p>

<pre><code>dic ['four'] = pd.DataFrame(np.maximum(dic['one'].values,dic['two'].values,dic['three'].values),columns = list('ABC'))
</code></pre>

python pandas numpy max where