selecting from multi-index pandas

后端 未结 6 474
庸人自扰
庸人自扰 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:34

    You can use DataFrame.loc:

    >>> df.loc[1]
    

    Example

    >>> print(df)
           result
    A B C        
    1 1 1       6
        2       9
      2 1       8
        2      11
    2 1 1       7
        2      10
      2 1       9
        2      12
    
    >>> print(df.loc[1])
         result
    B C        
    1 1       6
      2       9
    2 1       8
      2      11
    
    >>> print(df.loc[2, 1])
       result
    C        
    1       7
    2      10
    

提交回复
热议问题