python - 如何使用 vaderSentiment 包修复 Python 中的“编码”问题
问题描述
我正在处理一个情绪分析问题,并找到了 vaderSentiment 包,但无法让它运行。它给了我一个“编码”错误。
我尝试添加“从 io 导入打开”,但这并没有解决我的问题。请看下面的代码。
from io import open
from vaderSentiment.vaderSentiment import SentimentIntensityAnalyzer
analyser = SentimentIntensityAnalyzer()
def sentiment_analyzer_scores(sentence):
score = analyser.polarity_scores(sentence)
print("{:-<40} {}".format(sentence, str(score)))
sentiment_analyzer_scores("The phone is super cool.")
这是我想要的结果:
"The phone is super cool----------------- {'neg': 0.0, 'neu': 0.326, 'pos':
0.674, 'compound': 0.7351}"
我得到的结果:
File "<ipython-input-27-bbb91818db04>", line 6, in <module>
analyser = SentimentIntensityAnalyzer()
File "C:\Users\mr110e\AppData\Local\Continuum\anaconda2\lib\site
packages\vaderSentiment\vaderSentiment.py", line 212, in __init__
with open(lexicon_full_filepath, encoding='utf-8') as f:
TypeError: 'encoding' is an invalid keyword argument for this function
解决方案
推荐阅读
- sql-server - 有没有办法为 SQL Server 2014 标准版启用持续复制?
- c++ - 如何在编译时验证模板函数参数的类型
- timestamp - 将我的 bash 脚本的开始时间戳汇总到本周的每个星期一早上 7 点 PST
- blazor - 是否可以在网页中从 Blazor 的默认导航菜单中添加和删除菜单项?
- c++ - WAIT_TIMEOUT 后如何处理信号量
- go - 如何从结构中对 Dgraph 进行突变?
- flutter - 如何在 Flutter 上设置 tflite PoseNet“单人姿势估计”?
- python - StyleGAN2“您的会话在使用所有可用 RAM 后崩溃”在 Google Colab 培训开始时
- ios - 闭包在方法 mapValues 中是如何工作的?
- javascript - 将键映射添加到 Ace 编辑器的 vim 模式