【问题标题】:Sentiment Analysis in Python - TextBlobPython 中的情感分析 - TextBlob
【发布时间】:2020-08-14 00:32:38
【问题描述】:

我还是 python 和学习的新手,我的一门课程希望我使用 TextBlob 和 Pandas 对 cvs 文件进行情绪分析。到目前为止我所做的我将附在此处:

Import csv
from textblob import TextBlob
import pandas as pd

df = pd.read_csv('Movie_reviews.csv', delimiter='\t', header=None)

Movie_review_texts = df[2]
Movie_review_texts

for intex, review_text in enumerate (Movie_review_texts):
    blob = TextBlob(review_text)
    print('Analysing review\t', review_text)
    for sentence in blob.sentences: 
        print('--------SENTIMENT OF SENTENCE--------')
        print(sentence, '\t', sentence.sentiment.polarity)
        print('-------END-------')

但是我现在需要做的是聚合组成句子的情感分数,然后将聚合分数转换为布尔值。我真的很挣扎,我准备在这一点上放弃!

【问题讨论】:

  • 你能解释一下aggregate the sentiment scores of the constituent吗?
  • 所以基本上这段代码给了我每个句子自己的值,而一篇评论是建立在多于一个句子的形式。所以我需要做的是为每条评论给出一个汇总值,而不是把每一个句子分开。

标签: python pandas analysis textblob


【解决方案1】:

到目前为止,一切都很好。这是我的一项工作,它将帮助您执行所需的操作。

from vaderSentiment.vaderSentiment import SentimentIntensityAnalyzer
import time
analyzer = SentimentIntensityAnalyzer()

pos_count = 0
pos_correct = 0

with open("D:/Corona_Vac/pythonprogramnet/Positive BOW.txt","r") as f:
    for line in f.read().split('\n'):
        vs = analyzer.polarity_scores(line)
        if not vs['neg'] > 0.1:
            if vs['pos']-vs['neg'] > 0:
                pos_correct += 1
            pos_count +=1


neg_count = 0
neg_correct = 0

with open("D:/Corona_Vac/pythonprogramnet/Positive BOW.txt","r") as f:
    for line in f.read().split('\n'):
        vs = analyzer.polarity_scores(line)
        if not vs['pos'] > 0.1:
            if vs['pos']-vs['neg'] <= 0:
                neg_correct += 1
            neg_count +=1

print("Positive accuracy = {}% via {} samples".format(pos_correct/pos_count*100.0, pos_count))
print("Negative accuracy = {}% via {} samples".format(neg_correct/neg_count*100.0, neg_count))

希望你能找到方法。谢谢。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-03-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-10-07
    相关资源
    最近更新 更多