Apr-19-2017, 05:49 PM
Hello.
The input to the below two functions are a list of string sentences delimited by a comma from a csv file. Each list represents negative and positive tweets. When i append the 'negative' and 'positive' string sentiments they are being added to the end of each sentence, however I need to have the sentiment added to the end of each word. The structure I'm aiming for is to have a list of binomial tuples where each tuple consists of a word and the sentiment. Like this [ ('word', 'positive'), ('word2', 'positive'), ('word3, 'positive') ] ...
This is my current output but I would like the sentiment to be attached to each word rather than each sentence.
The input to the below two functions are a list of string sentences delimited by a comma from a csv file. Each list represents negative and positive tweets. When i append the 'negative' and 'positive' string sentiments they are being added to the end of each sentence, however I need to have the sentiment added to the end of each word. The structure I'm aiming for is to have a list of binomial tuples where each tuple consists of a word and the sentiment. Like this [ ('word', 'positive'), ('word2', 'positive'), ('word3, 'positive') ] ...
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 |
pos_sentences2 = clean1(pos_sentences) neg_sentences2 = clean1(neg_sentences) def append_pos(): temp = [] for row in pos_sentences2: temp.append((row, 'positive' )) return temp def append_neg(): temp = [] for row in neg_sentences2: temp.append((row, 'negative' )) return temp pos = append_pos() neg = append_neg() print (pos) |
Output:[(' omg its already O', 'positive'), (' Juuuuuuuuuuuuuuuuussssst Chillin ', 'positive'), (' handed in my uniform today i miss you already', 'positive'), (' hmmmm i wonder how she my number - ', 'positive')]
Thanks.