【发布时间】:2018-01-28 12:14:18
【问题描述】:
我正在尝试确定是否在 dataframe 中找到了两个变量
table:
Code index
600.SI 4th Q 2015
500.SI Full Year
ggr.SI 1st Q 2016
# If variable_code and variable_date is not found in table, print not found
if table['Code'].str.contains(variable_code).any() & table['index'].str.contains(variable_date).any():
print('found')
else:
print('not found')
但是,它总是返回我found。
我认为我的 if 语句的结构不正确,无法对两个项目进行 bool 比较。
如何解决?
更新
通常,variable_code 将在 table 中找到。如果在table 中找到variable_code,请检查variable_date 是否也存在。
我想要实现的是,如果这两个条件都不存在,请打印not found。
【问题讨论】:
-
抱歉,我不在,所以无法测试解决方案/响应。非常感谢您帮助回答,我很快就会给他们一个机会! :)
标签: python string pandas dataframe text