I have a table that is looks like follows:
name type val
A online 12
B online 24
A offline 45
B online 32
A offline 43
B offline 44
I want to dataframe
in such a manner that it can be groupby
with multiple cols name
& type
, which also have additional columns that return the count
of the record with val
being added of the same type records. It should be like follows:
name type count val
A online 1 12
offline 2 88
B online 2 56
offline 1 44
I have tried pd.groupby(['name', 'type'])['val'].sum()
that gives the addition but unable to add the count of records.