Merge lists across multiple rows by an identifier in Pandas

python pandas
Jan 9, 202408:55 PM173 views
0

Problem

Let's say we have the following dataframe. ```markdown | | name | items | |---:|:-------|:-------------------| | 0 | A | ['item1', 'item2'] | | 1 | A | ['item3', 'item4'] | | 2 | B | ['item5'] | | 3 | B | ['item6'] | | 4 | C | ['item7', 'item8'] | ``` How do we merge the lists by the column `name`? What we want is a dataframe that looks like the following. ```markdown | | name | items | |---:|:-------|:-------------------------------------| | 0 | A | ['item1', 'item2', 'item3', 'item4'] | | 1 | B | ['item5', 'item6'] | | 2 | C | ['item7', 'item8'] | ```
Menu