我有以下DataFrame。
Date Cleaned tweets
2018-05-23 [media, want, pravda, exist, write, aicle, tel...
2018-05-23 [yeah, think, great, work]
2018-05-23 [exactly, uaw, individual, stock, ownership, p...
2018-05-23 [um, tweeted, obv]
2018-05-23 [thank, thought, obvious]
我为以下内容创建了一个用于Textblob情感分析的python模块:
class TextBlobSentimentAnalysis:
def analyze_sentiment_polarity(self,word):
sentiment_analysis = TextBlob(word)
if sentiment_analysis.sentiment.polarity > 0:
return 1
elif sentiment_analysis.sentiment.polarity == 0:
return 0
else:
return -1
def analyze_sentiment_subjectivity(self,tweet):
subjectivity_analysis = TextBlob(tweet)
if subjectivity_analysis.sentiment.subjectivity >0:
return 1
elif subjectivity_analysis.sentiment.subjectivity ==0:
return 0
else:
return -1
我的问题是我想做的是分析每个单元格列表中每个单词的情感,然后计算其均值,以便对DataFrame的每一行仅具有一个极性值和一个主观性。每当我尝试访问单词,并且对每个单词进行情感处理时,我都会将每个列表中所有单词的情感综合在一起,并且无法将它们从一个列表中区分出来。
我试图做的是以下事情:
import statistics
for list_of_words in df['Cleaned tweets']:
polarity = []
for word in list_of_words:
polarity += [TextBlob_Analyzer.analyze_sentiment_polarity(word)]
avg_per_tweet = [statistics.mean(polarity)]
但是它只给我一个值,等于零。
Textblob_Analyzer是我所谓的TextblobSentimentAnalysis类。