My DataFrame has two columns:
Name Status
a I am Good
b Goodness!!!
c Good is what i feel
d Not Good-at-all
I want to filt
If you're defining "exact" to mean no other characters (including punctuation which defines a word boundary \b
), you could instead check for a leading and trailing space and/or beginning/end anchors:
>>> df[df['Status'].str.contains(r'(?:\s|^)Good(?:\s|$)')]
Name Status
0 a I am Good
2 c Good is what i feel
Explanation:
(?:\s|^)
is a non-capturing group looking for a space character (\s
) or the beginning of the string (^
).
Good
is the word you're looking for.
(?:\s|$)
is a non-capturing group looking for a space character (\s
) or the end of the string ($
).