The parameter,allWords, contains two column and thousands of rows. The first column tweet. The second one contains a sentiment( 0 for negative and 4 for positive.
As the bottom code shows I have created two dictionaries(negative & positive) to store the word in the dictionary with their frequency.
if you run the code it shows as it follows:
This is for negative dictionary {'transit': 1, 'infect': 4, 'spam': 6}
This is for positive dictionary {'transit': 3, 'infect': 5, 'spam': 2}
def vectorRepresentation(allWords):
negative = {}
positive = {}
for (t,s) in allWords:
if(s=='0'):
for w in t:
if w in negative:
negative[w]+=1
else:
negative[w]=1
if(s=='4'):
for w in t:
if w in positive:
positive[w]+=1
else:
positive[w]=1
print(negative)
print(positive)
However, I want to create one dictionary and store the two values for the same key. For example
newDictionary = {'transit': [1][3], 'infect': [4][5], 'spam': [6][2]}
The first value represents the negative. While, the second value is for positive. How can achieve that?