The latest version of Pandas supports multi-index sliders. However, to use them properly, you need to know the integer arrangement of different levels.
eg. following:
idx = pd.IndexSlice
dfmi.loc[idx[:,:,['C1','C3']],idx[:,'foo']]
assumes that we know that the third row level is the one we want to index with C1and C3, and the second column level is the one we want to index with foo.
Sometimes i know the names , but not their location in the multi-index. Is there a way to use multi-index slices in this case?
For example, say that I know the fragments that I want to apply for each level name, for example. like a dictionary:
'level_name_1' -> ':'
'level_name_2' -> ':'
'level_name_3' -> ['C1', 'C3']
() . Pandas ?
- pd.IndexSlice, , ?
PD: , reset_index(), , ( ). query, query , Python (, ..).
, :
df.xs('C1', level='foo')
foo - , C1 - .
, xs , :
df.xs(('one', 'bar'), level=('second', 'first'), axis=1)
(, pd.IndexSlice).