title: Sort dataframe multiindex level and by column
body: <p>#Updated:  pandas version 0.23.0 solves this problem with</p>
  <p><a href="https://pandas.pydata.org/docs/whatsnew/v0.23.0.html#sorting-by-a-combination-of-columns-and-index-levels" rel="nofollow noreferrer">Sorting by a combination of columns and index levels</a></p>
  <hr />
  <p>I have struggled with this and I suspect there is a better way.  How do I sort the following dataframe by index level name 'idx_0', level=0 and by column, 'value_1' descending such that the column 'MyName' reads vertical 'SCOTTBOSTON'.</p>
  <pre><code>import pandas as pd
  import numpy as np
  df = pd.DataFrame({'idx_0':[2]*6+[1]*5,
                     'idx_1':[6,4,2,10,18,5,11,1,7,9,3],
                     'value_1':np.arange(11,0,-1),
                     'MyName':list('BOSTONSCOTT')})
  
  df = df.set_index(['idx_0','idx_1'])
  df
  </code></pre>
  <p>Output:</p>
  <pre><code>            MyName  value_1
  idx_0 idx_1                
  2     6          B       11
        4          O       10
        2          S        9
        10         T        8
        18         O        7
        5          N        6
  1     11         S        5
        1          C        4
        7          O        3
        9          T        2
        3          T        1
  </code></pre>
  <p>#Excepted output using:</p>
  <pre><code>df.sort_values(['value_1'], ascending=False)\
    .reindex(sorted(df.index.get_level_values(0).unique()), level=0)
  </code></pre>
  <p>I suspect there is an easier way without resetting indexes</p>
  <pre><code>            MyName  value_1
  idx_0 idx_1                
  1     11         S        5
        1          C        4
        7          O        3
        9          T        2
        3          T        1
  2     6          B       11
        4          O       10
        2          S        9
        10         T        8
        18         O        7
        5          N        6
  </code></pre>
  <h3>Failure #1:</h3>
  <pre><code>df.sort_values('value_1', ascending=False).sort_index(level=0)
  </code></pre>
  <p>Sort by values first then sort index level=0, but level=1 get sorted also.</p>
  <pre><code>            MyName  value_1
  idx_0 idx_1                
  1     1          C        4
        3          T        1
        7          O        3
        9          T        2
        11         S        5
  2     2          S        9
        4          O       10
        5          N        6
        6          B       11
        10         T        8
        18         O        7
  </code></pre>
  <h3>Failure #2</h3>
  <pre><code>df.sort_index(level=0).sort_values('value_1', ascending=False)
  </code></pre>
  <p>Sort by index level=0 then sort by values, but index=0 gets jumbled again.</p>
  <pre><code>            MyName  value_1
  idx_0 idx_1                
  2     6          B       11
        4          O       10
        2          S        9
        10         T        8
        18         O        7
        5          N        6
  1     11         S        5
        1          C        4
        7          O        3
        9          T        2
        3          T        1
  </code></pre>