我有以下python数据框
for Landing_Page in zip(df.Landing_Page):
# the url
if "/2019/" in Landing_Page:
new_model_core_incentives = Landing_Page
print(f"new_model_core_incentives {new_model_core_incentives}")
elif re.search("/(?:(?:20)|(?:19))\d{2}/", url):
used_model_core_incentives = Landing_Page
print(f"used_model_core_incentives {used_model_core_incentives}")
# the "keywords"
if "2019" in Keyword:
new_word = Keyword
print(f"new_word {new_word}")
elif re.search("(?:(?:20)|(?:19))\d{2}", Keyword) is None:
old_word = Keyword
print(f"old_word {old_word}")
当我尝试分别运行这些块时,我遇到了一个问题,尽管所有URL中都包含“ / 2019 /”,但它们仍被归类为“ used_model_core_incentives”。
我也根本无法使用该功能来查看关键字块。
有什么想法吗?
答案 0 :(得分:0)
elif re.search("(?:(?:20)|(?:19))\d{2}", Keyword) is None:
缺少前斜线应该是:
elif re.search("/(?:(?:20)|(?:19))\d{2}/", Keyword) is None:
编辑:
就像@ s3n0一样,您确定Keyword
是字符串吗?我已经测试了这两种情况,并且在两种情况下都可以执行。