问题描述
这是对每种语法
的情感分数进行计数的功能,我遇到此错误
this is a function of counting sentimental score of each syntaxand i am getting this error
Traceback (most recent call last):
File "C:/Users/Public/Downloads/Hotelsurvey.py", line 116, in <module>
Countswordofeachsyntax()
File "C:/Users/Public/Downloads/Hotelsurvey.py", line 92, in Countswordofeachsyntax
print(findsentimentalscore(nopunct))
File "C:/Users/Public/Downloads/Hotelsurvey.py", line 111, in findsentimentalscore
ss =ss + weight
TypeError: unsupported operand type(s) for +: 'int' and 'list'
def Countswordofeachsyntax():
nopunct = ""
with open('dataset-CalheirosMoroRita-2017.csv', 'r') as csv_file:
csv_reader = csv.reader(csv_file, delimiter='|')
for sys in csv_reader:
for value in sys:
nopunct = ""
for ch in value:
if ch not in punctuation:
nopunct = nopunct + ch
print(findsentimentalscore(nopunct))
推荐答案
它看起来像是您试图向<$ c $中的列表添加int一样c> ss = ss + weight ,也许尝试将 ss
转换为整数,因为我怀疑您想要一个数字而不是可能的字符串,但是如果您可以使用 findsentimentalscore()
的代码更新问题所在的位置,那么可以更轻松地找到实际的问题。
It seams like you are trying to add a int to a list in ss = ss+weight
, maybe try typecasting ss
to a integer as i suspect you want a number instead of what is possibly a sting, but if you can update your question with the code for findsentimentalscore()
where problem seam to be, then that would make it easier to locate the actual problem.
好,您认为这可能是权重问题,请尝试以下 ss = ss + int(weight)
okay from the edit you suggested it might be weight that is the problem, try this ss = ss + int(weight)
这篇关于我正在尝试计算csv文件每种语法的感性得分的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!