Good evening! I have a dataframe with columns "dialog_id", "type" and "message". Each row on the df is basically one message description. I want to group this df, so it would show me how many messages of each type each dialog_id had sent. dialog_id is in strings, message is int(it's just a column of 1). So, what do I have now:
| dialog_id| message |type | | -------- | -------- |------ | name1 | 1 |video| | name1 | 1 |text | | name2 | 1 |audio| 2)What I want to achive(expected output). Here 1 row is a describtion of one dialog_id, not message
dialog_id | video | text | more types | total sent messages |
---|---|---|---|---|
name1 | 15 | 20 | x | 35+x |
name2 | 17 | 3 | y | 20+y |
Main problem is counting each type for each dialog.Groupby counts either each dialog or each type
aggregation_functions = {'message': 'sum', 'type': 'first', 'dialog_id':'first'}
df_n = df_var.groupby('dialog_id').aggregate(aggregation_functions)
but this and other variatons don't really work. Please help