title: Python Pandas - Selecting specific rows based on the max and min of two columns with the same group id
body: <p>I am looking for a way to identify the row that is the 'master' row. The way I am defining the master row is for each group id the row that has the minimum in cust_hierarchy then if it is a tie use the row with the most recent date.</p>
  <p>I have supplied some sample tables below:</p>
  <div class="s-table-container">
  <table class="s-table">
  <thead>
  <tr>
  <th style="text-align: left;">row_id</th>
  <th style="text-align: center;">group_id</th>
  <th style="text-align: right;">cust_hierarchy</th>
  <th style="text-align: right;">most_recent_date</th>
  <th style="text-align: right;">master(I am looking for)</th>
  </tr>
  </thead>
  <tbody>
  <tr>
  <td style="text-align: left;">1</td>
  <td style="text-align: center;">0</td>
  <td style="text-align: right;">2</td>
  <td style="text-align: right;">2020-01-03</td>
  <td style="text-align: right;">1</td>
  </tr>
  <tr>
  <td style="text-align: left;">2</td>
  <td style="text-align: center;">0</td>
  <td style="text-align: right;">7</td>
  <td style="text-align: right;">2019-01-01</td>
  <td style="text-align: right;">0</td>
  </tr>
  <tr>
  <td style="text-align: left;">3</td>
  <td style="text-align: center;">1</td>
  <td style="text-align: right;">7</td>
  <td style="text-align: right;">2019-05-01</td>
  <td style="text-align: right;">0</td>
  </tr>
  <tr>
  <td style="text-align: left;">4</td>
  <td style="text-align: center;">1</td>
  <td style="text-align: right;">6</td>
  <td style="text-align: right;">2019-04-01</td>
  <td style="text-align: right;">0</td>
  </tr>
  <tr>
  <td style="text-align: left;">5</td>
  <td style="text-align: center;">1</td>
  <td style="text-align: right;">6</td>
  <td style="text-align: right;">2019-04-03</td>
  <td style="text-align: right;">1</td>
  </tr>
  </tbody>
  </table>
  </div>
  <p>I was thinking of possibly ordering by the two columns (cust_hierarchy (ascending), most_recent_date (descending), and then a new column that places a 1 on the first row for each group id?</p>
  <p>Does anyone have any helpful code for this?</p>