我正在尝试在 python 中使用 VADER 确定客户反馈的情绪分数。下面的简单代码非常适合个人反馈,并返回一个包含负面、中性、正面和复合分数的字典。
代码:
from vaderSentiment.vaderSentiment import SentimentIntensityAnalyzer
feedback = "Food was very good"
vader = SentimentIntensityAnalyzer()
sentiment = vader.polarity_scores(feedback)
print(sentiment)
结果:{'neg':0.0,'neu':0.484,'pos':0.516,'compound':0.4927}
现在,我有一个包含 4k+ 客户反馈的电子表格。我要做的是遍历每个反馈并添加 4 个新列作为 Negative_Score、Neutral_Score、Positive_Score 和 Compound_Score。我编写了以下代码,但没有给出预期的结果。每行获得相同的分数。任何帮助将不胜感激。
代码:
import os.path
from vaderSentiment.vaderSentiment import SentimentIntensityAnalyzer
import pandas as pd
data = pd.read_excel(r"C:\...\sample_feedback.xlsx")
#Sample_feedback.xlsx has two col customer and feedbacktext
vader = SentimentIntensityAnalyzer()
data["Negative_Score"] = vader.polarity_scores(data["feedbacktext"]).get("neg")
data