我仍然是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-------')然而,我现在需要做的是聚合组成句子的情感分数,然后将聚合分数转换为布尔值。这是我真的真的在努力,我准备放弃在这一点上!
发布于 2020-05-09 01:22:31
到目前为止,这一切都很好。这是我的工作之一,它将帮助您执行您正在寻找的。
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))希望你能找到路。谢谢。
https://stackoverflow.com/questions/61509951
复制相似问题