from cnsenti import Emotion
def emotion_score(s):
senti = Sentiment()
r = senti.sentiment_count(str(s))
if r['pos']>r['neg']:
score = 1
elif r['pos'] < r['neg']:
score = -1
else :
score = 0
return score
all_df['情感得分'] = all_df['文本'].progress_apply(emotion_score)
错误提示:name “Sentiment” is not defined
你没写这一行,导入Sentiment就好了
from cnsenti import Sentiment
你使用的是 Sentiment 函数
import 导入的却是 Emotion 没有导入Sentiment函数
from cnsenti import Emotion
改成
from cnsenti import Sentiment
或者
from cnsenti import Emotion, Sentiment
`
from cnsenti import Sentiment #导入Sentiment函数
def emotion_score(s):
senti = Sentiment()
r = senti.sentiment_count(str(s))
if r['pos']>r['neg']:
score = 1
elif r['pos'] < r['neg']:
score = -1
else :
score = 0
return score
all_df['情感得分'] = all_df['文本'].progress_apply(emotion_score)
`> 如有帮助,请点击我的回答下方的【采纳该答案】按钮帮忙采纳下,谢谢!
Sentiment() 这个函数没有定义呢,这个函数在哪里?
您好,我是有问必答小助手,您的问题已经有小伙伴帮您解答,感谢您对有问必答的支持与关注!