Using .loc with a MultiIndex in pandas?

后端 未结 2 1402
爱一瞬间的悲伤
爱一瞬间的悲伤 2020-12-28 13:59

Does anyone know if it is possible to use the DataFrame.loc method to select from a MultiIndex? I have the following DataFrame and would like to be able to access the values

2条回答
  •  天命终不由人
    2020-12-28 14:27

    Try the cross-section indexing:

    In [68]: df.xs('at', level='QGram', drop_level=False).loc[[1,4]]
    Out[68]: 
            Char  Dwell  Flight  ND_Offset  Offset
    QGram                                         
    at    1    t    180       0   0.108363       5
          4    a     20     180   0.000000       0
    

提交回复
热议问题