Mar-22-2017, 11:30 PM
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:
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).