title: pandas pivot table descending order python
body: <p>i have a dataset that i read in with </p>
  
  <pre><code>data = pd.excel('.../data.xlsx)
  </code></pre>
  
  <p>then i organized everthing with pivot table</p>
  
  <pre><code>newdata = data.pivot_table(index=["Block", "Conc", "Replicate"], columns=["Name"], values="F532Mean-B532") '
  </code></pre>
  
  <p><strong>the Pivot table looks like this (the actual table's format is a little bit different than this, i typed the table in manually here:</strong></p>
  
  <pre><code>Block     conc      replicate     nameA    nameB   nameC ..     
  
    1                     
              0           1           2225     12     333   
                          2           3        423    52
                          3           53       88     239
             0.01         1           24       53     923
                          2           454      253    53
                          3           4        5      23
             10           1           34       53     923
                          2           44       253    53
                          3           11       49     232
     2
              0           1           234      634     39 
    .....
  </code></pre>
  
  <p><strong>everything looks good except i want the 'Conc' column to be in descending order, so instead of 0, 0.01, 10  , i would like it to be 10, 0.01, 0.</strong> </p>
  
  <pre><code> Conc 
    10
  
    0.01
  
     0
    ...
  </code></pre>
  
  <p>i have searched online and found a couple of posts with this kind of code:</p>
  
  <pre><code>  key1 = newdata.index.labels[0]
    key2 = newdata['Concentration'].rank(ascending=False)
    sorter = np.lexsort((key2, key1))
    sorted_df = newdata.take(sorter)
  
    sorted_df.to_excel('pivottable.xlsx')
  </code></pre>
  
  <p>the it gave me </p>
  
  <pre><code>KeyError: 'Concentration' 
  </code></pre>
  
  <p>i think the problem is that the online examples are all only 2 levels, here i have more than 2 level. what's a way around this?</p>