title: Pandas groupby and sort max values
body: <p>I am trying to <code>groupby</code> two <code>Columns</code> in a <code>pandas</code> <code>df</code> and return the <code>max</code> value. I'm then hoping to sort these <code>max</code> values in relation to the same <code>Columns</code>. </p>
  
  <p>This is my attempt:</p>
  
  <p>import pandas as pd</p>
  
  <pre><code>d = ({
  'year' : ['2016','2016','2016','2016','2016','2015','2015','2015','2015','2014','2014','2014','2014'],        
      'Val' : ['A','B','D','T','S','D','T','T','U','T','T','V','C'],                 
      'Num' : [1,2,4,5,3,6,4,3,2,5,6,1,2],                                     
      })
  
  df = pd.DataFrame(data = d)
  
  df = df.groupby(['year','Val']).Num.max()
  </code></pre>
  
  <p>Output:</p>
  
  <pre><code>year  Val
  2014  C      2
        T      6
        V      1
  2015  D      6
        T      4
        U      2
  2016  A      1
        B      2
        D      4
        S      3
        T      5
  </code></pre>
  
  <p>I have tried this to produce the following</p>
  
  <pre><code>df = df.sort_values(['year','Num'], ascending=False)
  </code></pre>
  
  <p>Intended Output:</p>
  
  <pre><code>year  Val
  2014  T      6
        C      2
        V      1
  2015  D      6
        T      4
        U      2
  2016  T      5
        D      4
        S      3
        B      2
        A      1
  </code></pre>