Input df:
title desc
movie A It is a awesome movie with action
movie B Slow but intense movie.
I want to filter rows which contains the following keywords:
keys = ["awesome", "action"]
Output DF:
title desc
movie A It is a awesome movie with action
Code:
index_list = []
for index,rows in df.iterrows():
if any(x in rows["desc"].split(" ") for x in keys) == True:
index_list.append(index)
df = df.loc[index_list]
Approach:
In each row, I am checking if any of the keywords are present after splitting the rows
This approach works fine, but I am interested to know if there is any one liner in pandas to achieve the same.
Example:
df.loc[df['column_name'].isin(some_values)]