Background
I have a big data frame with 2 levels columns, but 1 level rows, and I am trying to sort it as follows: level 0: alphabetically; level 1: custom sort.
Example
import pandas as pd
dictionary = {'A' : {'M': [1,2,3,4,5],
'L': [6,7,8,9,1],
'F': [3,5,1,3,5] },
'C' : {'M': [2,3,4,5,6],
'L': [7,8,9,1,2],
'F': [0,1,6,3,5] },
'B' : {'M': [1,5,2,5,3],
'L': [9,5,6,3,4],
'F': [6,2,7,1,5] }
}
reform = {(outerKey, innerKey): values for outerKey, innerDict in dictionary.iteritems() for innerKey, values in innerDict.iteritems()}
pd.DataFrame(reform,index=['g','h','i','j','k'])
What I have then is
# A B C
# F L M F L M F L M
# g 3 6 1 6 9 1 0 7 2
# h 5 7 2 2 5 5 1 8 3
# i 1 8 3 7 6 2 6 9 4
# j 3 9 4 1 3 5 3 1 5
# k 5 1 5 5 4 3 5 2 6
Question
How can I specify the order of columns to be A, B, C on level 0 and F, M, L on level 1?
### OUT
# A B C
# F M L F M L F M L
I was trying with pd.IndexSlice and .loc, but I still get only alphabetic order.