Through R, I can easily make a data frame containing the frequencies of certain string patterns from string lists.
library(stringr)
library(tm)
library(dplyr)
text = c('i am so hhappy happy now','you look ssad','sad day today','noway')
dat = sapply(c('happy', 'sad'), function(i) str_count(text, i))
dat = data.frame(dat)
dat = dat %>% mutate(Sentiment = (happy)-(sad))
As a result, I can have a data frame like this
happy sad Sentiment
1 2 0 2
2 0 1 -1
3 0 1 -1
4 0 0 0
In Python, I can assume rest of codes except sapply()
import pandas as pd
text = ['i am so hhappy happy now','you look ssad','sad day today','noway']
????
dat = pd.DataFrame(dat)
dat['Sentiment'] = dat.apply(lambda c: c.happy - c.sad)
What would ???? be?