diff --git a/server/stat_gen.py b/server/stat_gen.py index f2f5ae6..b63d377 100644 --- a/server/stat_gen.py +++ b/server/stat_gen.py @@ -198,6 +198,15 @@ class StatGen: if col.startswith("emotion_") and col != "emotion_neutral" ] + counts = ( + self.df[ + (self.df["topic"] != "Misc") + ] + .groupby("topic") + .size() + .rename("n") + ) + avg_emotion_by_topic = ( self.df[ (self.df["topic"] != "Misc") @@ -207,6 +216,11 @@ class StatGen: .reset_index() ) + avg_emotion_by_topic = avg_emotion_by_topic.merge( + counts, + on="topic" + ) + return { "word_frequencies": word_frequencies.to_dict(orient='records'), "average_emotion_by_topic": avg_emotion_by_topic.to_dict(orient='records')