Skip to content
Advertisement

Create table by grouping mean values by column and list of one-hot encoded columns (Python, pandas)

I am working with tweets and I would like to report the mean sentiment score by topic and by community.

This is what my dataframe looks like where each row is a document (tweet):

JavaScript

I want to create a dataframe that contains a mean sentiment value in each cell like this:

JavaScript

Any thoughts on how to go about this please? Thanks!

Advertisement

Answer

First you want to propagate the sentiment through the topic, then average out by community_id:

JavaScript
User contributions licensed under: CC BY-SA
5 People found this is helpful
Advertisement