【发布时间】:2020-06-10 09:15:44
【问题描述】:
对于当前的项目,我计划使用 TextBlob 对多个单词组合进行情绪分析。
当运行情感分析行polarity = common_words.sentiment.polarity 并使用 print(i, word, freq, polar) 调用结果时,我收到以下错误消息:
polarity = common_words.sentiment.polarity
AttributeError: 'list' object has no attribute 'sentiment'
是否有任何聪明的调整来让它运行?对应的代码部分如下所示:
for i in ['Text_Pro','Text_Con','Text_Main']:
common_words = get_top_n_trigram(df[i], 150)
polarity = common_words.sentiment.polarity
for word, freq in common_words:
print(i, word, freq, polarity)
编辑:请在下面找到该情况的完整解决方案(根据与用户 leopardxpreload 的讨论):
for i in ['Text_Pro','Text_Con','Text_Main']:
common_words = str(get_top_n_trigram(df[i], 150))
polarity_list = str([TextBlob(i).sentiment.polarity for i in common_words])
for element in polarity_list:
print(i, element)
for word, freq in common_words:
print(i, word, freq)
【问题讨论】:
-
common_words是list,而不是具有sentiment函数的对象。
标签: python nlp sentiment-analysis textblob