python可迭代類型,python中int對象不可迭代_python - 情感分析接收錯誤:'int'對象不可迭代_python-3.x_酷徒編程知識庫...

 2023-10-08 阅读 28 评论 0

摘要:我在csv文件上運行情感分析,并且收到這個錯誤消息,這是我的代碼:def sentimentAFINN(text):words = pattern_split.split(text.lower())sentiments = len(list(map(lambda word: afinn.get(word, 0), words)))if sentiments:python可迭代類型、s

我在csv文件上運行情感分析,并且收到這個錯誤消息,

這是我的代碼:def sentimentAFINN(text):

words = pattern_split.split(text.lower())

sentiments = len(list(map(lambda word: afinn.get(word, 0), words)))

if sentiments:

python可迭代類型、sentiment = float(sum(sentiments))/math.sqrt(len(sentiments))

else:

sentiment = 0

return sentiment

def sentimentDisplayValue(sentimentScore):

if sentimentScore > 0.1:

python中的int。return"Positive"

elif sentimentScore < -0.1:

return"Negative"

else:

return"Neutral"

totals = defaultdict(int)

python對象?for (index, row) in data.iterrows():

text = row['comment']

text_munged = munger(text)

sentimentScore = sentimentAFINN(text_munged)

sentimentDisplay = sentimentDisplayValue(sentimentScore)

totals[sentimentDisplay] = totals[sentimentDisplay] + 1

python sorted函數?pt.add_row([text_munged, sentimentScore, sentimentDisplay])

print (pt)

print (totals)

這是錯誤消息:TypeError Traceback (most recent call last)

in

4 text = row['LikelyToReferComment']

迭代器 python,5 text_munged = munger(text)

----> 6 sentimentScore = sentimentAFINN(text_munged)

7 sentimentDisplay = sentimentDisplayValue(sentimentScore)

8 totals[sentimentDisplay] = totals[sentimentDisplay] + 1

in sentimentAFINN(text)

29 sentiments = len(list(map(lambda word: afinn.get(word, 0), words)))

python sorted?30 if sentiments:

---> 31 sentiment = float(sum(sentiments))/math.sqrt(len(sentiments))

32

33 else:

TypeError: 'int' object is not iterable

版权声明:本站所有资料均为网友推荐收集整理而来,仅供学习和研究交流使用。

原文链接:https://hbdhgg.com/5/129767.html

发表评论:

本站为非赢利网站,部分文章来源或改编自互联网及其他公众平台,主要目的在于分享信息,版权归原作者所有,内容仅供读者参考,如有侵权请联系我们删除!

Copyright © 2022 匯編語言學習筆記 Inc. 保留所有权利。

底部版权信息