pythonpandasvader

Output vader sentiment scores in columns based on dataframe rows of tweets


I have a dataframe that contains rows of tweets and i would like to create 4 columns of the scores 'positive', 'negative', 'neutral' and 'compound' based on the content of each row using vader sentiment analysis.

I looked up different posts but i couldnt figure it out for my exact case. Thank you in advance!


Solution

  • I actually found a simple solution to do it through list comprehensions for anyone facing the same problem:

    analyzer = SentimentIntensityAnalyzer()
    df['compound'] = [analyzer.polarity_scores(x)['compound'] for x in df['tweet']]
    df['neg'] = [analyzer.polarity_scores(x)['neg'] for x in df['tweet']]
    df['neu'] = [analyzer.polarity_scores(x)['neu'] for x in df['tweet']]
    df['pos'] = [analyzer.polarity_scores(x)['pos'] for x in df['tweet']]