这是一个由两部分组成的代码问题。
1。)需要对csv文件执行情感分析以供客户审查。
2。)需要对保存为.txt的哈利·波特书评进行情感分析
1。)此数据框的名称为“评论”,我想做的是在“已发送”列下显示这5条评论中每条评论的情感评分。非常感谢!!!如果您可以在代码的“已发送”列中提供每一行的情感分析评分,那就太棒了!
reviews.head()
ID Customer Name Review Sent
1 Jack Beautiful cover up. My only
feedback is that it is a tad larger
than expected, but since it's a cover
up, it doesn't need to be fitted. The
waist tassels also allow you to adjust
to fit your waist which is nice.
Otherwise, its exactly as expected!
2 Rachel This tunic is very cute in person. It's
more sheer than I'd like, but I imagine
I'll wear it a ton on vacation.
3 Ryan Just got this sweet little dress in
blue. It's a great little dress for a
pool cover up. I can envision myself
wearing it on our winter getaway for
breakfast or on a walk. I'm not sure how
see through it is. I think I could get
away wearing it as a dress. The length
is great, not too short. The quality is
great. I got a size S. Fits true to size.
I am usually a size 2, 34b, 129lb, slim
build. Very happy with this.
4 Jennifer Love this hat! Kept the sun off my face
and neck/chest in the intense tropical
sun! Choose white - so I stayed cool.
5 Alex What I like about bikinis is that they
always fit you perfectly. You won't
realize how gorgeous they are and how
attractive they make your body look
until you put one on. As for the bra-part
it gives good support and sits well. I
also like the fabric: it stretches well
without losing its shape, the color
doesn't fade. This bikini is no exception.
is far better at making bikinis than
anybody else, I would say!
对于这个字符串,我只是想知道总体情绪得分是多少...谢谢!
2。)
“父母需要知道,《哈利·波特与魔法石》是一部激动人心的故事,这是JK罗琳的《哈利·波特》系列中的第一篇。它尊重孩子们的智力,并激发他们应对更大的篇幅和复杂性,玩耍这是该系列中最轻的游戏,但仍对敏感的读者来说有些可怕的东西:三头狗,攻击性巨魔,猛烈的真人大小的国际象棋棋盘,戴头巾的人物死亡和流血的独角兽,以及关于哈利父母多年前去世的讨论。”
答案 0 :(得分:0)
对于任何其他有关stackoverflow不是代码编写服务的问题,请记住,您应该始终提供一些您自己尝试过的代码。
TextBlob是具有sentiment analysis的python软件包,可为您返回给定文本的极性和主观性。要将这种情感分析功能应用于您的数据框,您需要使用对应的功能apply。
看看下面的例子:
import pandas as pd
from textblob import TextBlob
df = pd.DataFrame([['1', 'Jack', "Beautiful cover up. My only feedback is that it is a tad larger than expected, but since it's a cover up, it doesn't need to be fitted. The waist tassels also allow you to adjust to fit your waist which is nice. Otherwise, its exactly as expected!"],
['2', 'Rachel', "This tunic is very cute in person. It's more sheer than I'd like, but I imagine I'll wear it a ton on vacation."],
['3', 'Ryan', "Just got this sweet little dress in blue. It's a great little dress for a pool cover up. I can envision myself wearing it on our winter getaway for breakfast or on a walk. I'm not sure how see through it is. I think I could get away wearing it as a dress. The length is great, not too short. The quality is great. I got a size S. Fits true to size. I am usually a size 2, 34b, 129lb, slim build. Very happy with this."],
['4', 'Jennifer', "Love this hat! Kept the sun off my face and neck/chest in the intense tropical sun! Choose white - so I stayed cool."],
['5', 'Alex', "What I like about bikinis is that they always fit you perfectly. You won't realize how gorgeous they are and how attractive they make your body look until you put one on. As for the bra-part it gives good support and sits well. I also like the fabric: it stretches well without losing its shape, the color doesn't fade. This bikini is no exception. is far better at making bikinis than anybody else, I would say!"]], columns=['ID', 'CustomerName', 'Review'] )
df['sent'] = df['Review'].apply(lambda x: TextBlob(x).sentiment)
#you can get the polarity and subjectivty values in separate columns by splitting
df['polarity'] = df['sent'].str[0]
df['subjectivity'] = df['sent'].str[1]
关于第二个问题,只需执行以下命令:
TextBlob("Parents need to know that Harry Potter and the Sorcerer's Stone is a thrill-a-minute story, the first in J.K. Rowling's Harry Potter series. It respects kids' intelligence and motivates them to tackle its greater length and complexity, play imaginative games, and try to solve its logic puzzles. It's the lightest in the series, but it still has some scary stuff for sensitive readers: a three-headed dog, an attacking troll, a violent life-size chess board, a hooded figure over a dead and bleeding unicorn, as well as a discussion of how Harry's parents died years ago.").sentiment
答案 1 :(得分:0)
嗨,我在Java和javascript中都做了类似的项目
为了分析不同的字段,我使用了n-gram算法 “ https://sentimentanalyservibhor.000webhostapp.com/ngram.html”
ngram git repo: https://github.com/dev-vibhor/SentimentAnalysis_JavaScript/blob/master/index.html
使用JavaScript(N-GRAM)实现Bi Gram
牛 牛跳 跳过 在 月亮
例如: text =酒店的食物很好吃
如果N = 3(TRI-GRAM)并且关键字==食物
我会得到一个结果
关键字'food'=积极的总体情绪
youtube:https://www.youtube.com/watch?v=qMe8wB8sOds
邮件:vibsin95@outlook.com