Check if a value exists in pandas dataframe index

前端 未结 6 817
轮回少年
轮回少年 2020-12-23 13:17

I am sure there is an obvious way to do this but cant think of anything slick right now.

Basically instead of raising exception I would like to get True

6条回答
  •  夕颜
    夕颜 (楼主)
    2020-12-23 13:29

    Just for reference as it was something I was looking for, you can test for presence within the values or the index by appending the ".values" method, e.g.

    g in df..values
    g in df.index.values
    

    I find that adding the ".values" to get a simple list or ndarray out makes exist or "in" checks run more smoothly with the other python tools. Just thought I'd toss that out there for people.

提交回复
热议问题