Python中的情感分析-TextBlob

问题描述 投票:0回答:1

我仍然不熟悉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-------')

但是我现在需要做的是汇总构成句子的情感分数,然后将合计分数转换为布尔值。我真的很挣扎,现在我准备放弃!

python pandas analysis textblob
1个回答
0
投票

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

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))

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

© www.soinside.com 2019 - 2024. All rights reserved.