Vader Sentiment值未正确显示

时间:2016-08-08 01:00:27

标签: python sentiment-analysis

我使用维达情绪来分析充满推文的CSV文件。我尝试获得整套推文的每个情绪值的平均值。出于某种原因,许多结果倾向于出现0值,除非它是一个舍入问题,否则它没有意义。 len(result [i])总是返回1.我的代码如下:

for row in csv.reader(csv_file):
    result = { 'pos':[] , 'neg':[], 'compound':[], 'neu':[] }
    sentences = row
    f = open(file_name[0], 'a', newline='')
    writer = csv.writer(f)
    for sentence in sentences:
        vs = vaderSentiment(sentence)
        row = [sentence, str(vs)]
        writer.writerow(row)
        result['pos'].append(vs['pos'])
        result['neg'].append(vs['neg'])
        result['compound'].append(vs['compound'])
        result['neu'].append(vs['neu'])
print('sum:')
for i in result.keys():
    print('\t',i, '=>', float(sum(result[i]))/len(result[i]))
f.close()

1 个答案:

答案 0 :(得分:0)

没关系,我意识到我愚蠢地放置了结果= {'pos':[],'neg':[],'compound':[],'neu':[]}我不应该这样做在循环的每次迭代中清除数据。我不敢相信我花了这么长时间才弄明白......