【发布时间】:2018-10-13 14:14:20
【问题描述】:
我对推文进行了情绪分析,但现在我必须将情绪附加到推文文本中的每个单词。我的情绪分析是基于字典中出现的单词的总和。我希望这个例子可以帮助到你。
我尝试使用此功能,但在这里不起作用。
def append_sentiment(sentences, sentiment):
return [(word, sentiment) for sentence in sentences
for word in sentence.split()]
append_sentiment(df['text'], df['score'])
例子:
id | text | score
12 | I like this | 2
想要的结果:
id | text | score
12 | ('I', 2), ('like', 2), ('this', 2) | 2
【问题讨论】:
标签: python pandas dataframe sentiment-analysis