VaderSentiment Python软件包中所有分数的零值错误

我有一个数据框,我将其转换为称为transcript的字符串格式

transcript
Out[90]: "0    thank you for calling my name is Britney and h...\n1    thank you %HESITATION and then %HESITATION you...\n2                              what is last week this \n3    so did you want to cancel it effective the ten...\n4                                         %HESITATION \n5    please leave it there on file all right and th...\n6    %HESITATION no no I don't I just want to let y..."

type(transcript)
Out[91]: str

我正在尝试使用VaderSentiment软件包对此进行情感分析

from vaderSentiment.vaderSentiment import SentimentIntensityAnalyzer
import pandas as pd
analyser = SentimentIntensityAnalyzer()

def print_sentiment_scores(alist):
    for aSentence in alist: 
      asnt = analyser.polarity_scores(aSentence[0])
      print(str(asnt))

df_before = print_sentiment_scores(your_list)

print_sentiment_scores(your_list)


def print_sentiment_scores(alist):
    polarity_scores = []
    for aSentence in alist: 
        asnt = analyser.polarity_scores(aSentence[0])
        print(str(asnt))
        polarity_scores += [asnt]

    return polarity_scores

output_df = pd.DataFrame(print_sentiment_scores(your_list))

我没有收到错误,但是输出中的所有分数都显示为0,这是不正确的:

{'neg': 0.0,'neu': 0.0,'pos': 0.0,'compound': 0.0}
{'neg': 0.0,'compound': 0.0}

我要去哪里错了?我该如何解决?

sinochun 回答:VaderSentiment Python软件包中所有分数的零值错误

因为每个文本仅使用第一个字符。请删除代码中的[0]。 正确的代码是:

def print_sentiment_scores(alist):
for aSentence in alist: 
  aSnt = analyser.polarity_scores(aSentence)
  print(str(aSnt))
本文链接:https://www.f2er.com/2466463.html

大家都在问