检查pandas dataframe index中是否存在值 [英] Check if a value exists in pandas dataframe index

查看:5635
本文介绍了检查pandas dataframe index中是否存在值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我确信有一种明显的方法可以做到这一点,但现在不能想到任何光滑的东西。

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

基本上不是提出异常我想得到 True False 查看pandas中是否存在值 df index 。

Basically instead of raising exception I would like to get True or False to see if a value exists in pandas df index.

df = pandas.DataFrame({'test':[1,2,3,4]}, index=['a','b','c','d'])

df.loc['g']  # (should give False)

我现在的工作是以下

sum(df.index == 'g')


推荐答案

这应该可以做到这一点

'g' in df.index

这篇关于检查pandas dataframe index中是否存在值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆