1

Suppose I have

enter image description here

I want to create a new dataframe by doing a Group By on Account and Date and putting the names together in one cell.

Thus at the end of the day we should have

Account    Name             Date

1          Bob, Rob, Joe     1/1/2020

I am not sure how to do this in Python

Snorrlaxxx
  • 168
  • 1
  • 3
  • 18

1 Answers1

1

Iiuc you search for df.groupby(...).agg(list) - but you don't make it clear if you aim for a string concatenation or a list of names...

df.groupby(['Account', 'Date'], as_index=False).Name.agg(list)

#    Account      Date             Name
# 0        1  1.1.2020  [Bob, Rob, Joe]
SpghttCd
  • 10,510
  • 2
  • 20
  • 25