我确信有一个明显的方法可以做到这一点,但现在想不出任何巧妙的方法。
基本上不是引发异常,我想获取 True
或 False
以查看 Pandas df
索引中是否存在值。
import pandas as pd
df = pd.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
关于python - 检查 Pandas 数据框索引中是否存在值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23549231/