Im using jupyter notebooks, my current dataframe looks like the following:
players_mentioned | tweet_text | polarity
______________________________________________
[Mane, Salah] | xyz | 0.12
[Salah] | asd | 0.06
How can I group all players individually and average their polarity?
Currently I have tried to use:
df.groupby(df['players_mentioned'].map(tuple))['polarity'].mean()
But this will return a dataframe grouping all the mentions when together as well as separate, how best can I go about splitting the players up and then grouping them back together.
An expected output would contain
player | polarity_average
____________________________
Mane | 0.12
Salah | 0.09
In other words how to group by each item in the lists in every row.