I'm having the following dataframe.
| Fruit | Description |
|---|---|
| Apple | ["red", "big"] |
| Banana | ["yellow", "long"] |
| Banana | ["elongated, twisted"] |
| Peach | ["round"] |
| Apple | ["round", "greenish"] |
And I'm trying to group by the descriptions according to the fruit, through a concatenation of the lists. I should obtain that:
| Fruit | Description |
|---|---|
| Apple | ["red", "big", "round", "greenish"] |
| Banana | ["yellow", "long", "elongated, twisted"] |
| Peach | ["round"] |
I followed the solution provided here: pandas groupby and join lists:
df = df.groupby('Fruit', as_index=False).agg(Description =('Description', 'sum'))
but what I'm obtaining are lists attached to each other:
| Fruit | Description |
|---|---|
| Apple | ["red", "big"]["round", "greenish"] |
| Banana | ["yellow", "long"]["elongated, twisted"] |
| Peach | ["round"] |
Does anyone have a solution? Thanks!