Collectives™ on Stack Overflow
Find centralized, trusted content and collaborate around the technologies you use most.
Learn more about Collectives
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
Learn more about Teams
lst1=['spot','mistake']
lst1_tweets=tweets[tweets['tweet_text'].str.contains('|'.join(lst1))].reset_index()
I want to double check and have:
f=lst1_tweets['tweet_text'][0]
f='Spot the spelling mistake Welsh and Walsh. You are showing picture of presenter Bradley Walsh who is alive and kick'
type(f)
<class 'str'>
I used
f.str.contains('|'.join(lst1))
returns:
AttributeError: 'str' object has no attribute 'str'
f.contains('|'.join(lst1))
returns:
AttributeError: 'str' object has no attribute 'contains'
Any suggestions how I can search for a list of words in a string
–
–
–
–
You might be confusing .str.contains()
from pandas, which exists and is applied to series. In this case you can use in
or not in
operators.
Here's a full guide on how to address the issue Does Python have a string 'contains' substring method?
From pandas docs:
Series.str.contains(self, pat, case=True, flags=0, na=nan, regex=True).
Test if pattern or regex is contained within a string of a Series or Index.
Not too sure if you're just checking for certain strings in a string, but i'm pretty sure .contains isn't a python thing,
try this:
for "string" in f:
# do whatever
–
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.