【问题标题】:NLTK polarity_scoresNLTK 极性分数
【发布时间】:2021-05-15 12:15:46
【问题描述】:

我想知道我是否可以让 Sentimentia.polarity_scores() 函数只打印负数、正数,并且我可以摆脱中性和复合结果

    i = 0
    while i < len(Replaced_Data):
        Sentimentia = SentimentIntensityAnalyzer()
        print(Sentimentia.polarity_scores(data['Clean_TweetText'][i]))
        i = i + 1

output >>> {'neg': 0.214, 'neu': 0.534, 'pos': 0.252, 'compound': 0.25}

desired output >>> {'neg': 0.214, 'pos': 0.188}

【问题讨论】:

  • 你可以试试ss = Sentimentia.polarity_scores(data['Clean_TweetText'][i]) print({e:ss[e] for e in ss if e in ['neg','pos']})
  • @simpleApp 非常感谢你,完美运行,救命
  • @simpleApp 您介意将其添加为答案以便我验证吗?这将使更多人更容易看到
  • 不客气!

标签: python nltk sentiment-analysis


【解决方案1】:

可以使用Dictionary Comprehensions从字典中过滤'neg'和'pos'

ss = Sentimentia.polarity_scores(data['Clean_TweetText'][i])     
print({e:ss[e] for e in ss if e in ['neg','pos']})

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2019-10-06
    • 2018-01-28
    • 2012-01-28
    • 1970-01-01
    • 1970-01-01
    • 2015-04-28
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多