'Pandas - sort MultiIndex

I want to sort the column 'block' in each category: first neu, and then neg and to present the desctiptives in this order: mean, std, skew

Part of my dataset is:

        count_number    count_number    count_number    mean_intensity  mean_intensity  mean_intensity
        mean    skew    std mean    skew    std
category    block                       
Total Body Map  neg 19.31541219 7.564192592 31.99056986 1.609429405 1.214868757 0.606236866
Total Body Map  neu 19.83453237 9.137008077 37.2249668  1.752317126 1.253237673 0.635625642
blue    neg 2.899641577 5.303464527 6.086070298 0.811997431 1.384440223 0.960788564
blue    neu 3.510791367 5.18138759  7.153668526 0.948385322 0.709322925 0.967728961

and the expected data set it:

        count_number    count_number    count_number    mean_intensity  mean_intensity  mean_intensity
        mean    std skew    mean    std
category    block                       
Total Body Map  neu 19.83453237 9.137008077 37.2249668  1.752317126 1.253237673 0.635625642
Total Body Map  neg 19.31541219 7.564192592 31.99056986 1.609429405 1.214868757 0.606236866
blue    neu 3.510791367 5.18138759  7.153668526 0.948385322 0.709322925 0.967728961
blue    neg 2.899641577 5.303464527 6.086070298 0.811997431 1.384440223 0.960788564

this is the current indexing:

MultiIndex([('Total Body Map', 'neg'),
        ('Total Body Map', 'neu'),
        (          'blue', 'neg'),
        (          'blue', 'neu'),
        (          'grey', 'neg'),
        (          'grey', 'neu'),
        (           'red', 'neg'),
        (           'red', 'neu'),
        (         'hands', 'neg'),
        (         'hands', 'neu'),
        (          'head', 'neg'),
        (          'head', 'neu'),
        (          'legs', 'neg'),
        (          'legs', 'neu'),
        (         'torso', 'neg'),
        (         'torso', 'neu')],
        names=['category', 'block'])


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source