Search code examples
pythonkeywordkeyword-search

How to check if keyword is present in title or not in Python?


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:

for string in df['key']:
    test = df['title'].str.contains(string,case=False, na=False) 
    print(test)

Sample dataset:

dataset

Expected Output:

output


Solution

  • 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')