title: Top Bottom pairings based on column values in a pandas dataframe
body: <p>I would like to generate Sector/Group wise pairs from a DataFrame based on the values in it's Score column. </p>
  
  <pre><code>+---------+-------------------+---------+
  |  Ticker |      Sector       |   Score |   
  +---------+-------------------+---------+
  |   ABC   |    Energy         |    3.5  |     
  |   XYZ   |    Energy         |    4.5  |     
  |   PQR   |    Tech           |    5.5  |     
  |   MNP   |    Tech           |    1.5  |     
  |   JKL   |    Energy         |   10.5  |     
  |   BCA   |    Energy         |    8.5  |     
  |   RDB   |    Tech           |    6.5  |
  |   JMP   |    Tech           |    2.5  |
  +---------+-------------------+---------+
  </code></pre>
  
  <p>From above example in sector Energy JKL/ABC would be one such pairing as JKL is highest and ABC is lowest scorer in that sector.Similarly next pairing within Energy  would be BCA/XYZ as BCA is second highest and XYZ is the second lowest within that sector.</p>
  
  <p>As a next step I would like to retain those pairs within each sector where the pair-difference is greater than a certain threshold.</p>
  
  <p>Thank you for your help.</p>
  
  <p>Output can be </p>
  
  <pre><code>+---------+-------------------+---------+
  |  Ticker |      Sector       |  Result |   
  +---------+-------------------+---------+
  |   ABC   |    Energy         |    0    |     
  |   XYZ   |    Energy         |    0    |     
  |   PQR   |    Tech           |    1    |     
  |   MNP   |    Tech           |    0    |     
  |   JKL   |    Energy         |    1    |     
  |   BCA   |    Energy         |    1    |     
  |   RDB   |    Tech           |    1    |
  |   JMP   |    Tech           |    0    |
  +---------+-------------------+---------+
  </code></pre>