0

在情感分析之后,我过滤了最大的 5 条具有最大极性的推文。

maxx = df.nlargest(5,['polarity']).astype(str)
maxx

输出:

Unnamed: 0  clean_tweet Tweet_tokenized polarity    subjectivity    Sentiment_Type  scores  compound    sentiment_type  pca
315 315 Best of। luck Biden   best / luck biden   1.0 0.3 POSITIVE    {'neg': 0.0, 'neu': 0.122, 'pos': 0.878, 'comp...   0.802   POSITIVE    [-0.06151099614792966, -0.030998756958434074]

现在我想创建一些wordcloud,但出现错误:

hero.wordcloud(maxx, max_words=100)
AttributeError: 'DataFrame' object has no attribute 'str'
4

1 回答 1

1

基于极性排序

df['polarity'] = df['polarity'].astype('float')   
maxx = df.nlargest(5, 'polarity')

如果你使用wordcloud包试试这个

from wordcloud import WordCloud

text_data = ' '.join(maxx['clen_tweet']) 

wordcloud = WordCloud().generate(text_data)
plt.imshow(wordcloud2)
plt.axis("off")
plt.show()

使用texthero

import texthero as hero

hero.wordcloud(maxx['clean_tweet'], max_words=100)
于 2021-04-28T07:26:52.230 回答