如何将文本文件读入python中的情感分析函数?

2024-09-24 21:23:07 发布

您现在位置:Python中文网/ 问答频道 /正文

我是python的新手,正在尝试使用vaderthiotation库进行情绪分析。你知道吗

from vaderSentiment.vaderSentiment import SentimentIntensityAnalyzer

analyser = SentimentIntensityAnalyzer()

def print_sentiment_scores(sentence):
    snt = analyser.polarity_scores(sentence)
    print("{:-<40} {}".format(sentence, str(snt)))

print_sentiment_scores("I just got a call from my boss - does he realise it's Saturday?")

我刚接到老板的电话-他知道今天是星期六吗?{'neg':0.0,'neu':1.0,'pos':0.0,'compound':0.0}

如你所见,应用程序运行,但只有当我手动输入文本。我如何使它读取一个ms word文件的文本,甚至csv文件给我的所有文本在该文件中的最终情感分数?你知道吗


Tags: 文件from文本importsentenceprint情绪sentiment