嗨,我正在尝试使用情感分类器包对某些文本文件进行分类。以下程序可以很好地处理单个句子,即
from senti_classifier import senti_classifier
sentences = ['i love u']
pos_score, neg_score = senti_classifier.polarity_scores(sentences)
print pos_score, neg_score
但是,当通过以下方式通过使用xls文件对每条记录进行分类时,对于正值和负值,结果均为0.0。
请帮帮我。
import openpyxl
from senti_classifier import senti_classifier
wb = openpyxl.load_workbook('sentiment2.xlsx')
sheet = wb.active
sheet.columns[0]
for cellObj in sheet.columns[0]:
sentences = cellObj.value
print(sentences)
pos_score, neg_score = senti_classifier.polarity_scores(sentences)
print pos_score, neg_score
最佳答案
senti_classifier.polarity_scores()
function需要一个字符串列表作为参数,但是您要传递一个字符串。将其放入列表中:
pos_score, neg_score = senti_classifier.polarity_scores([sentences])