0

I have data that looks like this:

service   |  company
--------------------
sequencing|  Fischer
RNA tests |  Fischer
Cell tests|  23andMe
consulting|  UCLA
DNA tests |  UCLA
mouse test|  UCLA

and I want to concat services together into a list on equal company names like this:

service_list                           |  company
-------------------------------------------------
['sequencing','RNA tests']             |  Fischer
['Cell tests']                         |  23andMe
['consulting','DNA tests','mouse test']|  UCLA

Not sure how to begin doing this.

Trenton McKinney
  • 56,955
  • 33
  • 144
  • 158
Brian Guan
  • 193
  • 2
  • 12
  • 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) – Trenton McKinney Jan 14 '21 at 00:54

1 Answers1

2

Lets try groupby(), aggregate to list

df.groupby('company').service.agg(list).reset_index()




company                            service
0  23andMe                        [Celltests]
1  Fischer             [sequencing, RNAtests]
2     UCLA  [consulting, DNAtests, mousetest]
wwnde
  • 26,119
  • 6
  • 18
  • 32