0

{'rating': 5.0, 'reviewer_name': 'Sns073194', 'product_id': 'B00004RFRV', 'review_title': 'Perfect cafsito every time', 'review_time': '03 11, 2018', 'images': ['https://images-na.ssl-images-amazon.com/images/I/71d2cQEgJsL._SY88.jpg'], 'styles': {'Size:': ' 6-Cup', 'Color:': ' Silver'}}

{'rating': 2.0, 'reviewer_name': 'Sns073194', 'product_id': 'B00004RFRV', 'review_title': 'Horrible', 'review_time': '03 11, 2018', 'images': ['https://images-na.ssl-images-amazon.com/images/I/71d2cQEgJsL._SY88.jpg'], 'styles': {'Size:': ' 6-Cup', 'Color:': ' Silver'}}

{'rating': 3.0, 'reviewer_name': 'Sns073194', 'product_id': 'B00004RFRV', 'review_title': 'Great', 'review_time': '03 11, 2018', 'images': ['https://images-na.ssl-images-amazon.com/images/I/71d2cQEgJsL._SY88.jpg'], 'styles': {'Size:': ' 6-Cup', 'Color:': ' Silver'}}

  • 1
    Please have a go at solving the problem yourself, stackoverflow doesn't do homework for you. If you have some code which you think should work but doesn't then would be the more appropriate time to submit a question here for help, otherwise, perhaps Fiverr or Freelancer. – G.S Feb 02 '22 at 14:17
  • 1
    You tagged both Python and R, which language did you want help in? It looks like you're fairly new to SO; welcome to the community! If you want great answers quickly, it's best to make your question reproducible. This includes sample data like the output from `dput(head(dataObject)))` in R. Check it out: [making R reproducible questions](https://stackoverflow.com/q/5963269) or [making reproducible questions, in general](https://stackoverflow.com/help/minimal-reproducible-example). – Kat Feb 02 '22 at 14:23
  • Please provide enough code so others can better understand or reproduce the problem. – Community Feb 10 '22 at 20:18

1 Answers1

1

What you could do is make a nested dictionnary. Such as :

ratings = {'rating1': {'rating': 5.0},
           'rating2': {'rating': 3.2}}

The idea is to create ids for ratings, and for each id rating key, you give as a value another dictionnary, with all the keys you already have, rating, reviewer_name and so on.

So with this you can easily count the positive, negative and neutral reviews. Here I'm assuming you already created the nested dictionnary.

# Dictionnary to keep track of positive, negative and neutral reviews
reviews = {'positive': 0, 'negative': 0, 'neutral': 0}
# rating is the dictionnary containing all your reviews (the nested dic)
for key in ratings.keys():
    if ratings[key]['rating'] >= 4:
        reviews['positive'] += 1
    elif ratings[key]['rating'] == 3:
        reviews['neutral'] += 1
    else:
        reviews['negative'] += 1
print(reviews)
arlaine
  • 199
  • 8