mardi 19 juillet 2016

Sum and count data from columns

I have a DataFrame like:

1        member_id  application_name  active_seconds 
2           192180             Opera   6
3           192180             Opera   7
4           192180             Chrome  243
5           5433112            Chrome   52
6           5433112            Opera   34
7           5433112            Chrome 465

And I try to group it.

I want to count application_name to id and sum active_seconds to application_name. I use df.groupby(['member_id', 'application_name'])['event_duration'].sum() and df.groupby(['member_id', 'application_name']).size() and second return to me correct value, but first return

       member_id  application_name  active_seconds
       192180             Opera             67
       192180             Chrome            243
       5433112            Chrome           52465
       5433112            Opera              34

What I do wrong?

Aucun commentaire:

Enregistrer un commentaire