1

A beginner in panda and trying to achieve this in a pandas data frame-

Input- Input

I want an output like-

Output

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

1
  • groupby + agg , search the key words like this Commented Mar 22, 2018 at 20:41

1 Answer 1

2

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
Sign up to request clarification or add additional context in comments.

2 Comments

Thanks, it works for me. Any suggestions to practice, so I can be as good as you :)
@Ayum Check out the book listed in my profile by Ted Petrou and look at Stack Overflow. If I helped you would you care to accept this answer.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.