title: Python Getting second largest element in each row of matrix
body: <p>I begin with a correlation matrix, which means the i,jth entry would be the correlation between the ith element and the jth element(So the diagonals would be 1). I am trying to find the maximum correlation for each element with another element(not including itself since a list of 1's isn't helpful in my case). </p>
  
  <pre><code>1    0.7  0.4  0.1
  0.7  1    0.3  0.2
  0.4  0.3  1    0.5
  0.1  0.2  0.5  1
  </code></pre>
  
  <p>Suppose I have the above matrix. I would like to have something like<br>
   (max correlation, ith element, jth element). In the above matrix, I would like to get<br>
  <code>[(0.7, 0, 1), (0.7, 1, 0), (0.5, 2, 3), (0.5, 3, 2)]</code><br>
  as a result. </p>
  
  <p>What would be a good way to go about this?<br>
  I have the matrix as a pandas dataframe. The index and columns have the same name, say <code>[0, 1, 2, 3]</code> for now. Currently I've only thought of doing something like </p>
  
  <pre><code>D = {}
  for i in df.columns:
      max = (0, 0, 0)
      for j in df.columns:
          if i==j:
             continue
          element = df.loc[i,j]
          if element &gt; max[0]:
             max = (element, i, j)
      D[i] = max
  </code></pre>
  
  <p>Can this be done better/faster, and are there built in methods that can improve this?</p>