需要帮助对客户评论和一串文本进行情绪分析

Need helping performing sentiment analysis on customer reviews and for a string of text

这是一道由两部分组成的代码题。

1.) 需要对客户评论的 csv 文件进行情绪分析。

2.) 需要对保存为 .txt 的哈利波特书评执行情感分析

1.) 这个 Dataframe 的名称是 "reviews",我想做的是在 "sent" 列下显示这 5 条评论中每条评论的情绪分数。太感谢了!!!如果您可以为代码提供 "sent" 列,其中每一行都填充了情绪分析分数,那就太棒了!!

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

"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."

请记住任何其他问题,Whosebug 不是代码编写服务,您应该始终提供一些您自己尝试过的代码。

TextBlob 是一个 python 包,它有一个 sentiment analysis and returns you a polarity and subjectivity of a given text. To apply this sentiment analysis function to your dataframe you need to use the corrospondent function 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

你好,我在 java 和 javascript

中做了一个类似的项目
  1. 你可以运行它“https://sentimentanalyservibhor.000webhostapp.com/
  2. git 回购:只需提取和 运行 index.html https://github.com/dev-vibhor/SentimentAnalysis_JavaScript/blob/master/SentimentAnalysisJS.zip
  3. 为了分析不同的领域我用过n-gram算法 “https://sentimentanalyservibhor.000webhostapp.com/ngram.html

  4. ngram git 回购: https://github.com/dev-vibhor/SentimentAnalysis_JavaScript/blob/master/index.html

    使用 JavaScript (N-GRAM)

    的 Bi Gram 实现

    文本的 N-gram 广泛用于文本挖掘和自然语言处理任务。它们基本上是给定 window 中的一组同时出现的单词,在计算 n-gram 时,您通常会向前移动一个单词(尽管在更高级的场景中您可以向前移动 X 个单词)。例如,对于句子 "The cow jumps over the moon"。如果 N=2(称为二元语法),则 n 元语法为:

    the cow cow jumps jumps over over the the moon


    例如: text=酒店食物不错

    如果 N=3(TRI-GRAM) 且关键字== food

    我会得到一个结果

    1. 酒店食物:中性,丢弃它
    2. 食物很好:好评

关键字的整体情绪 'food'=正面

YouTube:https://www.youtube.com/watch?v=qMe8wB8sOds

邮箱:vibsin95@outlook.com