微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

NLTKpolarity_scores

如何解决NLTKpolarity_scores

我想知道我是否可以让 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}

解决方法

可以使用 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']})

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。