(Apr-19-2017, 06:58 PM)zivoni Wrote: You need to split each sentence into words and then append pairs (word, sentiment) to your list. It can be done by adding another for loop into your original for loop,
for row in pos_sentences2: for word in row.split(): temp.append((word, 'positive'))but perhaps its easier do it with a list comprehension. And you dont need to implement basically same function for positive and negative sentiment, instead that you can use sentences and sentiment as parameters for your function.
def append_sentiment(sentences, sentiment): return [(word, sentiment) for sentence in sentences for word in sentence.split()]
Output:In [4]: sentences = ['omg its already 0', 'Juuust chillin'] In [5]: append_sentiment(sentences, 'positive') Out[5]: [('omg', 'positive'), ('its', 'positive'), ('already', 'positive'), ('0', 'positive'), ('Juuust', 'positive'), ('chillin', 'positive')]
Hi, please, what should I do to achieve the same if I have it in pandas dataframe and have positive or negative numbers to mark the score?
Example:
id | text | score
12 | I like this | 2
Wanted result:
id | text | score
12 | ('I', 2), ('like', 2), ('this', 2) | 2