python - Python 中的情感分析 - TextBlob
问题描述
我对 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-------')
但是我现在需要做的是我需要汇总组成句子的情感分数,然后将汇总分数转换为布尔值。我真的很挣扎,我准备在这一点上放弃!
解决方案
到目前为止,这很好。这是我的一项工作,它将帮助您执行您正在寻找的内容。
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))
希望你能找到方法。谢谢。
推荐阅读
- android - Android Horizontal Recyclerview 在滚动时显示多项选择
- javascript - 无法从响应获取中访问 JWT Web 令牌
- julia - 如何创建新的精灵应用程序?
- r - 根据数据框中的顺序创建颜色矢量列表
- bash - 分隔十进制数的整数和小数部分
- performance - Jmeter:将统计数据格式化为 HTML 报告中的逗号
- python - Python json.py 无法将字符串转换为字典
- java - 反射抛出 java.lang.IllegalStateException: zip 文件已关闭
- java - Apache Camel Java 8 支持
- css - chield flex-direction 行不起作用反应原生?