title: Find the difference between the max value and 2nd highest value within a subset of pandas columns
body: <p>I have a fairly large dataframe:</p>
  <div class="s-table-container">
  <table class="s-table">
  <thead>
  <tr>
  <th style="text-align: left;"></th>
  <th>A</th>
  <th>B</th>
  <th>C</th>
  <th>D</th>
  </tr>
  </thead>
  <tbody>
  <tr>
  <td style="text-align: left;">0</td>
  <td>17</td>
  <td>36</td>
  <td>45</td>
  <td>54</td>
  </tr>
  <tr>
  <td style="text-align: left;">1</td>
  <td>18</td>
  <td>23</td>
  <td>17</td>
  <td>17</td>
  </tr>
  <tr>
  <td style="text-align: left;">2</td>
  <td>74</td>
  <td>47</td>
  <td>8</td>
  <td>46</td>
  </tr>
  <tr>
  <td style="text-align: left;">3</td>
  <td>48</td>
  <td>38</td>
  <td>96</td>
  <td>83</td>
  </tr>
  </tbody>
  </table>
  </div>
  <p>I am trying to create a new column that is the (max value of the columns) - (2nd highest value) / (2nd highest value).</p>
  <p>In this example it would look something like:</p>
  <div class="s-table-container">
  <table class="s-table">
  <thead>
  <tr>
  <th style="text-align: left;"></th>
  <th>A</th>
  <th>B</th>
  <th>C</th>
  <th>D</th>
  <th>Diff</th>
  </tr>
  </thead>
  <tbody>
  <tr>
  <td style="text-align: left;">0</td>
  <td>17</td>
  <td>36</td>
  <td>45</td>
  <td>54</td>
  <td>.20</td>
  </tr>
  <tr>
  <td style="text-align: left;">1</td>
  <td>18</td>
  <td>23</td>
  <td>17</td>
  <td>17</td>
  <td>.28</td>
  </tr>
  <tr>
  <td style="text-align: left;">2</td>
  <td>74</td>
  <td>47</td>
  <td>8</td>
  <td>46</td>
  <td>.57</td>
  </tr>
  <tr>
  <td style="text-align: left;">3</td>
  <td>48</td>
  <td>38</td>
  <td>96</td>
  <td>83</td>
  <td>.16</td>
  </tr>
  </tbody>
  </table>
  </div>
  <p>I've tried df['diff'] = df.loc[:, 'A': 'D'].max(axis=1) - df.iloc[:df.index.get_loc(df.loc[:, 'A': 'D'].idxmax(axis=1))] / ...</p>
  <p>but even that part of the formula returns an error, nevermind including the final division.  I'm sure there must be an easier way going about this.</p>
  <p>Edit:  Additionally, I am also trying to get the difference between the max value and the column that immediately precedes the max value.  I know this is a somewhat different question, but I would appreciate any insight.  Thank you!</p>