selecting from multi-index pandas

后端 未结 6 466
庸人自扰
庸人自扰 2020-12-02 05:19

I have a multi-index data frame with columns \'A\' and \'B\'.

Is there is a way to select rows by filtering on one column of the multi-index without resetting the

6条回答
  •  攒了一身酷
    2020-12-02 05:45

    Another option is:

    filter1 = df.index.get_level_values('A') == 1
    filter2 = df.index.get_level_values('B') == 4
    
    df.iloc[filter1 & filter2]
    Out[11]:
         0
    A B
    1 4  1
    

提交回复
热议问题