Python Forum
Making a list for positive vs negative reviews based on rating
Thread Rating:
  • 1 Vote(s) - 1 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Making a list for positive vs negative reviews based on rating
#2
I suppose that you are using pandas dataframe...

Check dtype of your sentiment column, its quite possible that it is integer and both of your conditions evaluate as False (0 or 1 instead of "0" or "1" would work).

And iterating over rows of dataframe is very often a terrible idea (pandas and underlying numpy are optimized for vectorized operations with columns, iterating over rows is inefficient) and this is no exception of it. Following code should have same functionality as yours:

positive = data[data["sentiment"] == 1]["review"].tolist()

negative = data[data.sentiment == 0].review.tolist()     
# selecting columns with . is usually shorter, but doesnt work for "ugly" names (spaces/symbols/methods).
Reply


Messages In This Thread
RE: Making a list for positive vs negative reviews based on rating - by zivoni - Mar-22-2017, 11:30 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  How to recognize negative in a text? AlekseyPython 1 1,812 Oct-06-2021, 10:09 AM
Last Post: Larz60+
Question [Solved] How to refer to dataframe column name based on a list lorensa74 1 2,239 May-17-2021, 07:02 AM
Last Post: lorensa74
  negative selection algorithm mohammed 0 1,962 May-17-2020, 09:27 PM
Last Post: mohammed
  Calculate Rating Score for Reviews Containing Specific Words bongielondy 1 2,062 Nov-15-2019, 09:16 PM
Last Post: micseydel
  Making indices and rearrranging list reidybwoykeon 2 3,430 May-18-2017, 06:57 PM
Last Post: reidybwoykeon

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020