I have a simple data frame, and I am developing a sentiment analysis.
This is the code and the reproducible example
import transformers
from pysentimiento import SentimentAnalyzer
from pysentimiento import EmotionAnalyzer
analyzer = SentimentAnalyzer(lang="en")
emotion_analyzer = EmotionAnalyzer(lang="en")
data = [['Hello world'], ['I am the best'], ['Nice jacket!']]
df2 = pd.DataFrame(data, columns = ['Tweet'])
# print dataframe.
df2["sentiment"] = df2.apply(lambda row : analyzer.predict(row["Tweet"]), axis = 1)
The output for the code below:
Tweet sentiment
---------------------| --------------------
Hello world | SentimentOutput(output=POS, probas={POS: 0.999, NEG: 0.001,NEU: 0.000}) |
I am the best | SentimentOutput(output=POS, probas={POS: 0.999, NEG: 0.001,NEU: 0.000})
Nice jacket! | SentimentOutput(output=POS, probas={POS: 0.999, NEG: 0.001,NEU: 0.000})
I would like to split the sentiment column and have something like this:
Tweet sentiment prob_Pos Prob_Neg Prob_Neu
---------------------|---------------|----------|------------------------------
Hello world | POS | 0.99 | 0.001 | 0.000
I am the best | POS | 0.99 | 0.001 | 0.000
Nice jacket! | POS | 0.99 | 0.001 | 0.000