python - NLTK 极性分数
问题描述
我想知道我是否可以让 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']})
推荐阅读
- python - 使用 applescript 将消息发送到新的联系人/线程
- javascript - 尝试在我的 React 应用程序中使用链接但遇到问题
- inverse-kinematics - IK 的雅可比矩阵的两个伪逆矩阵之间的区别?
- python - Pandas:列值上的位移运算符(>>)
- c++ - 具有特定数据类型(如字符串)的多个模板的模板函数?
- php - PHP 会话变量在 Firefox 63.0、MacOS Mojave 上的 Safari 12.0 和 iOS 12.0.1 上的 Safari 中丢失
- linux - 无法安装快照
- java - 如何修复此错误操作数 (&&)
- sql - 使用 Join 优化 SQL 查询
- kernel - 如何在 2 个 FreeBSD 内核模块之间共享数据?