Reputation: 47
A beginner in panda and trying to achieve this in a pandas data frame-
Input- Input
I want an output like-
It is groupby on name columns, the merge all the rows in Address and in same row store the total count of address.
Any help is appreciated.
thanks
Upvotes: 1
Views: 746
Reputation: 153520
Use:
(df.groupby('Name', as_index=False)
.agg({'Count':'sum','Address':lambda x: ' \n '.join(x)}))
Output:
Name Address Count
0 Jake XXXXXXXXX \n YYYYYYYYY \n ZZZZZZZZZ 3
1 Jon AAAAAAA \n BBBBBBBB 2
Upvotes: 2