1

I am new to python and I have a dataset that looks like this

enter image description here

I am extracting the reviews from the dataset and trying to apply the VADER tool to check the sentiment weights associated with each review. I am able to successfully retrieve the reviews but unable to apply VADER to each review. This is the code

import nltk
    import requirements_elicitation
    from nltk.sentiment.vader import SentimentIntensityAnalyzer

c = requirements_elicitation.read_reviews("D:\\Python\\testml\\my-tracks-reviews.csv")
class SentiFind:
    def init__(self,review):
        self.review = review

for review in c:
    review = review.comment
    print(review)

sid = SentimentIntensityAnalyzer()
for i in review:
    print(i)
    ss = sid.polarity_scores(i)
    for k in sorted(ss):
        print('{0}: {1}, '.format(k, ss[k]), end='')
    print()

Sample output:

g
compound: 0.0, neg: 0.0, neu: 0.0, pos: 0.0, 
r
compound: 0.0, neg: 0.0, neu: 0.0, pos: 0.0, 
e
compound: 0.0, neg: 0.0, neu: 0.0, pos: 0.0, 
a
compound: 0.0, neg: 0.0, neu: 0.0, pos: 0.0, 
t
compound: 0.0, neg: 0.0, neu: 0.0, pos: 0.0, 

compound: 0.0, neg: 0.0, neu: 0.0, pos: 0.0, 
a
compound: 0.0, neg: 0.0, neu: 0.0, pos: 0.0, 
p
compound: 0.0, neg: 0.0, neu: 0.0, pos: 0.0, 
p

I need to customize the labels for each review as well to something like this

"Total weight: {0}, Negative: {1}, Neutral: {2}, Positive: {3}".
4

1 回答 1

2

review您定义的是 a ,string因此当您遍历它时,您会得到每个字母:

for i in review:
   print(i)

g
r
e
a...

因此,您将希望分析器进行每次审查:

sid = SentimentIntensityAnalyzer()

for review in c:
    review = review.comment
    ss = sid.polarity_scores(review)
    total_weight = ss.compound
    positive = ss.pos
    negative = ss.neg
    neutral = ss.neu
    print("Total weight: {0}, Negative: {1}, Neutral: {2}, Positive: {3}".format(total_weight, positive, negative, neutral))
于 2018-11-21T03:39:59.793 回答