Reputation: 419
Is there a way that str.contains
filter only the exact match of string rather than partial match
List = ['good', 'bad']
df
col
1 good
2 this is good
3 good boy
4 bad dream
5 goodman
6 badboy
7 bad
df[(df['col'].str.contains('|'.join(List),na=False, ))]
Desired output
1 good
6 bad
Upvotes: 1
Views: 968
Reputation: 82765
You can use isin
in this senario
Ex:
data = ['good', 'bad']
print(df[df['col'].isin(data)])
Output:
col
0 good
6 bad
Upvotes: 4