Pandas slicing along multiindex and separate indices

后端 未结 2 981
别跟我提以往
别跟我提以往 2021-02-08 20:11

I\'ve started using Pandas for some large Datasets and mostly it works really well. There are some questions I have regarding the indices though

  1. I have a MultiI

2条回答
  •  野趣味
    野趣味 (楼主)
    2021-02-08 20:54

    For the first part, you can use boolean indexing using get_level_values:

    df[df.index.get_level_values('a').isin([5, 7, 10, 13])]
    

    For the second two, you can inspect the MultiIndex object by calling:

    df.index
    

    (and this can be inspected/sliced.)

提交回复
热议问题