Pandas slicing along multiindex and separate indices

后端 未结 2 1010
别跟我提以往
别跟我提以往 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:44

    Edit: This answer for pandas versions lower than 0.10.0 only:

    Okay @hayden had the right idea to start with:

    An index has the method get_level_values() which returns, however, an array (in pandas versions < 0.10.0). The isin() method doesn't exist for arrays but this works:

    from pandas import lib
    lib.ismember(df.index.get_level_values('a'), set([5, 7, 10, 13])
    

    That only answers question 1 - but I'll give an update if I crack 2, 3 (half done with @hayden's help)

提交回复
热议问题