如何遍历TextBlob单词列表并找到最常见的名词?

2024-06-01 05:11:32 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在从Twitter上抓取推文,我想收集一个列表,列出所有我抓取的推文中的所有名词,这样我就可以找出哪些名词出现频率最高

def sentiment_script():


        for tweet in tweepy.Cursor(api.search, q=hashtag_phrase + ' -filter:retweets', lang="en", tweet_mode='extended').items(7):

                text = tweet.full_text

                text = ' '.join(re.sub("(@[A-Za-z0-9]+)|([^0-9A-Za-z \t])|(\w+:\/\/\S+)", " ", text).split())


                blob = TextBlob(text)

                nouns = (blob.noun_phrases)

                print(nouns)

输出如下:

['covid', 'richmitch']
['uk', 'england', 'uk', 'johnson', 's approach']
['peoria']
['pa', 'surely', 'secretly trying', 'infect', 'covid', 'never wonkette']
['don t', 'full lockdown', 'cancer etc don t', 'full recovery', 'death rate', 'aren t', 'full lockdown']
['datascience team', 'weekly report', 'new data', 'covid', 'may', 'report sheds light', 'business impacts', 'covid', 'read', 'capraplus']
['osdbu', 'small businesses', 'linked', 'covid']

我不确定下一步要做什么,因为当我这样做时:

print(type(nouns))

结果是

<class 'textblob.blob.WordList'>
<class 'textblob.blob.WordList'>
<class 'textblob.blob.WordList'>
<class 'textblob.blob.WordList'>
<class 'textblob.blob.WordList'>
<class 'textblob.blob.WordList'>
<class 'textblob.blob.WordList'>

Tags: textblobfullclasstweetprintdonwordlist