i am trying to calculate sentimental score of each syntax of csv file [duplicate]

拈花ヽ惹草 提交于 2020-07-10 07:41:06

问题


this is a function of counting sentimental score of each syntax and 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))

回答1:


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.

okay from the edit you suggested it might be weight that is the problem, try this ss = ss + int(weight)



来源:https://stackoverflow.com/questions/62657944/i-am-trying-to-calculate-sentimental-score-of-each-syntax-of-csv-file

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!