Quantcast
Channel: Active questions tagged python - Stack Overflow
Viewing all articles
Browse latest Browse all 23160

Groupby Method returning incorrect counts Pandas Python

$
0
0

enter image description here

As you can see in the screenshot, I can count the values of each possible value for the sentiment column, and then I can group the same data by the brand and the sentiment, but the values are obviously incorrect, since they don't add up with the total values for each sentiment.

brand_sentiment_train.sentiment.value_counts()pivot_df = (brand_sentiment_train.groupby(['brand', 'sentiment']).size()                                 .unstack(fill_value=0)            )pivot_df

I'm not smart enough to figure out what the issue is that is causing the groupby method to incorrectly group the sentiments with the brand, so I am hoping someone else can see what the error is. All I know is that it seems to be an issue with the groupby method.

I tried to group the data by sentiment and brand, and I was expecting to have the total amount of each sentiment add up to the same amount of each sentiment that I determined for the sentiment feature individually, but instead, the values are way off, and it appears that when I try to group by both sentiment and brand that somehow the sentiment is not being counted correctly.


Viewing all articles
Browse latest Browse all 23160

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>