Selecting rows from a Pandas dataframe with a compound (hierarchical) index

后端 未结 3 997
[愿得一人]
[愿得一人] 2020-12-07 12:05

I\'m suspicious that this is trivial, but I yet to discover the incantation that will let me select rows from a Pandas dataframe based on the values of a hierarchical key. S

3条回答
  •  独厮守ぢ
    2020-12-07 12:21

    Syntax like the following will work:

    df.ix['a']
    df.ix['a'].ix['c']
    

    since group1 and group2 are indices. Please forgive my previous attempt!

    To get at the second index only, I think you have to swap indices:

    df.swaplevel(0,1).ix['c']
    

    But I'm sure Wes will correct me if I'm wrong.

提交回复
热议问题