title: Python: select most frequent using group by
body: <p>How do I get the most frequently occurring category (mode) for each tag in Python?</p>
  
  <pre><code>+------------------+----------+
  | tag              | category |
  +------------------+----------+
  | automotive       |        8 |
  | ba               |        8 |
  | bamboo           |        8 |
  | bamboo           |        8 |
  | bamboo           |        8 |
  | bamboo           |        8 |
  | bamboo           |        8 |
  | bamboo           |       10 |
  | bamboo           |        8 |
  | bamboo           |        9 |
  | bamboo           |        8 |
  | bamboo           |       10 |
  | bamboo           |        8 |
  | bamboo           |        9 |
  | bamboo           |        8 |
  | banana tree      |        8 |
  | banana tree      |        8 |
  | banana tree      |        8 |
  | banana tree      |        8 |
  | bath             |        9 |
  +-----------------------------+
  </code></pre>
  
  <p>expected output would be like</p>
  
  <pre><code>    tag     | category 
  ------------+-----------
   ba         |        8      
   automotive |        8      
   bananatree |        8        
   bath       |        9    
   bamboo     |        8 
  </code></pre>
  
  <p>I have borrowed table from Stephen J. Fuhry and edited output from David Fuhry on <a href="https://stackoverflow.com/questions/1407723/mysql-select-most-frequent-by-group">MySQL SELECT most frequent by group</a> due to confidentiality of my data set.</p>