I have a dataset, df, where I would like to groupby two columns, take the sum and count of another column as well as list the strings in a separate column
Data
id date pwr type
aa q321 10 hey
aa q321 1 hello
aa q425 20 hi
aa q425 20 no
bb q122 2 ok
bb q122 1 cool
bb q422 5 sure
bb q422 5 sure
bb q422 5 ok
Desired
id date pwr count type
aa q321 11 2 hey
hello
aa q425 40 2 hi
no
bb q122 3 2 ok
cool
bb q422 15 3 sure
sure
ok
Doing
g = df.groupby(['id', 'date'])['pwr'].sum().reset_index()
g['count'] = g['id'].map(df['id'].value_counts())
This works ok, except, I am not sure how to display the string output of column 'type' Any suggestion is appreciated.