Check if a value exists in pandas dataframe index

前端 未结 6 808
轮回少年
轮回少年 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:31

    df = pandas.DataFrame({'g':[1]}, index=['isStop'])
    
    #df.loc['g']
    
    if 'g' in df.index:
        print("find g")
    
    if 'isStop' in df.index:
        print("find a") 
    

提交回复
热议问题