title: Get max of count() function on pandas groupby objects
body: <h3>Problem</h3>
  
  <p>Using pandas, I need to get back the row with the max count for each groupby object. </p>
  
  <h3>Dataset</h3>
  
  <p>I have a dataframe called "matches" that looks like this: </p>
  
  <p><code>FeatureID    gene  pos
  0        1_1_1  KRAS_1    6
  1        1_1_1  KRAS_2    8
  2        1_1_1  KRAS_3   11
  3        1_1_1  NRAS_1    3
  4        1_1_1  NRAS_2   11
  5        1_1_1  NRAS_3   84
  6       1_1_10  KRAS_1    4
  7       1_1_10  KRAS_2    3
  8       1_1_10  KRAS_3   14
  9       1_1_10  NRAS_1    4
  10      1_1_10  NRAS_2    6
  11      1_1_10  NRAS_3   83
  </code></p>
  
  <h3>What I've tried</h3>
  
  <p>I need to group together the dataframe by FeatureID and then get the count of positions in each group: </p>
  
  <pre><code>matches.groupby(["FeatureID", "gene"]).count()
  </code></pre>
  
  <p>Which results in:</p>
  
  <p><code>FeatureID gene
  1_1_1     KRAS_1    6
            KRAS_2    8
            KRAS_3   11
            NRAS_1    3
            NRAS_2   11
            NRAS_3   84
  1_1_10    KRAS_1    4
            KRAS_2    3
            KRAS_3   14
            NRAS_1    4
            NRAS_2    6</code></p>
  
  <h3>Desired output:</h3>
  
  <p>I need to get back the row in each groupby object that contains the highest count, but I cannot figure out how to do that.</p>
  
  <p><code>FeatureID gene count
  1_1_1 NRAS_3   84
  1_1_10 KRAS_3   14</code></p>
  
  <h3>Solution</h3>
  
  <p>The following line gives me back the gene with the max value for each groupby group: </p>
  
  <pre><code>matches.groupby(["FeatureID", "gene"]).count().sort_values("pos").groupby(level=0).tail(1)
  </code></pre>