title: Pandas: Sort multilevel column with mixed datatypes
body: <p>This is an extension to this <a href="https://stackoverflow.com/questions/64571500/pandas-sort-a-multiindex-dataframes-multi-level-column-with-mixed-datatypes"><code>previous</code></a> question of mine.</p>
  <p>Below is the df:</p>
  <pre><code>In [28]: df = pd.DataFrame({'A':['a','b:all:c','all:1:3','c','d','e'], 'D':[{&quot;value&quot;: '126', &quot;perc&quot;: None, &quot;unit&quot;: None}, {&quot;value&quot;: 324, &quot;perc&quot;: None, &quot;unit&quot;: None}, {&quot;value&quot;: 'N/A', &quot;perc&quot;: None, &quot;unit&quot;: None}, {}, {&quot;value&quot;: '100', &quot;perc&quot;: None, &quot;unit&quot;:
      ...:  None}, np.nan]})
      ...: 
  In [34]: df.columns = pd.MultiIndex.from_product([df.columns, ['E']])
  
  In [35]: df
  Out[35]: 
           A                                             D
           E                                             E
  0        a  {'value': '126', 'perc': None, 'unit': None}
  1  b:all:c    {'value': 324, 'perc': None, 'unit': None}
  2  all:1:3  {'value': 'N/A', 'perc': None, 'unit': None}
  3        c                                            {}
  4        d  {'value': '100', 'perc': None, 'unit': None}
  5        e                                           NaN
  </code></pre>
  <p>I need to sort the multi-level column with index <code>(D,E)</code> in descending order based on value key from dict.</p>
  <p><strong>But I need to leave the rows as it is that contain the substring <code>all</code> in all earlier columns.</strong></p>
  <p>As you can see value key can have values in mixed datatypes like int, string or empty like {}, or NaN.</p>
  <p>N/A and Nan values should always appear at last after sorting(both asc and desc).</p>
  <p>So, the <strong>expected output</strong> will be:</p>
  <pre><code>In [38]: df1 = pd.DataFrame({'A':['a','b:all:c','all:1:3','d','c','e'], 'D':[{&quot;value&quot;: '126', &quot;perc&quot;: None, &quot;unit&quot;: None}, {&quot;value&quot;: 324, &quot;perc&quot;: None, &quot;unit&quot;: None}, {&quot;value&quot;: 'N/A', &quot;perc&quot;: None, &quot;unit&quot;: None}, {&quot;value&quot;: '100', &quot;perc&quot;: None, &quot;unit&quot;: No
      ...: ne},{}, np.nan]})
      ...: 
  
  In [40]: df1.columns = pd.MultiIndex.from_product([df1.columns, ['E']])
  
  In [41]: df1
  Out[41]: 
           A                                             D
           E                                             E
  0        a  {'value': '126', 'perc': None, 'unit': None}
  1  b:all:c    {'value': 324, 'perc': None, 'unit': None}
  2  all:1:3  {'value': 'N/A', 'perc': None, 'unit': None}
  3        d  {'value': '100', 'perc': None, 'unit': None}
  4        c                                            {}
  5        e                                           NaN
  </code></pre>