英文:
How to check if keyword is present in title or not in Python?
问题
我有一个包含多个关键词的数据集,我想检查标题是否包含相同的关键词。匹配应该是逐行部分匹配。
我尝试了这段代码,但对印度语单词/关键词不起作用:
```python
for string in df['key']:
test = df['title'].str.contains(string, case=False, na=False)
print(test)
样本数据集:
期望输出:
<details>
<summary>英文:</summary>
I have a dataset which contains multiple keywords and I want to check if title contains the same key or not. it should be row by row partial match.
I have tried this code but it is not working for indic words/keys:
```python
for string in df['key']:
test = df['title'].str.contains(string,case=False, na=False)
print(test)
Sample dataset:
Expected Output:
答案1
得分: 0
我没有Indic键盘,但你尝试过简单的解决方案吗:
for line in list_of_lines:
if str(line['key']).lower() in str(line['title']).lower():
print('True')
else:
print('False')
英文:
I don't have Indic keyboard, but have you tried the easy solution:
for line in list_of_lines:
if str(line['key']).lower() in str(line['title']).lower():
print('True')
else:
print('False')
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论