'Calculate and return the average of positive, negative, and neutral
I have the following dataframe: enter image description here I am trying to have three additional columns in which they return sum of instances of 0, 1-, and 1 (positive negative and neutral per say). After that, I want to calculate the average sentiment of user's posts. Any help with appending these averages would be great.
So far I tried the solution below: def mean_positive(L): # Get all positive numbers into another list pos_only = [x for x in L if x > 0] if pos_only: return sum(pos_only) / len(pos_only) raise ValueError('No postive numbers in input')
Thank you.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|