I am analyzing tweets.
I have 10k tweets and am interested in a list of words occurring:
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'
also
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
.str.contains()
on a Pandas series, not after extracting an individual string.f
is referencing a Python string, whose class is namedstr
:type(f) is str
.pandas.Series.str
is a different class with different attributes, includingcontains
. You can check if a class has an attribute by a certain name (without raising an Exception, that is) with the built-in callablehasattr