0

How do I select a column that is grouped by other columns and put all the values of the column in 1 row (in a list). Input:

PropID    Manager    Manager_email      date
  1         A         a@aol.com       2021-02-01
  1         A         a@aol.com       2021-02-02
  1         A         a@aol.com       2021-02-03
  1         A         a@aol.com       2021-02-04
  2         B         b@aol.com       2021-02-08
  2         B         b@aol.com       2021-02-10
  2         B         b@aol.com       2021-02-12
  2         B         b@aol.com       2021-02-16

Desired Output:

PropID    Manager    Manager_email                      date
  1         A         a@aol.com       [2021-02-01,2021-02-02,2021-02-03,2021-02-04]
  2         B         b@aol.com       [2021-02-08,2021-02-10,2021-02-12,2021-02-16]
  • Does this answer your question? [How to group dataframe rows into list in pandas groupby](https://stackoverflow.com/questions/22219004/how-to-group-dataframe-rows-into-list-in-pandas-groupby) – Henry Ecker Jul 20 '21 at 00:32

1 Answers1

4

try this:

df.groupby(['PropID','Manager','Manager_email'])['date'].agg(list)
rhug123
  • 7,893
  • 1
  • 9
  • 24