How to group by a dataframe and concatenate by a column

Question:

I have a df with the following structure:

Store Sku Value
1 A 20
2 A 20
1 B 10
2 B 25

And I have to transform it, so that the stores with the same sku and same value, end up concatenated in a cell with a "-" separator like the following.

Store Sku Value
1 – 2 A 20
1 B 10
2 B 25

How can I approach this?

Asked By: Juan1403

||

Answers:

Groupby the sku and value and then list the store

df.groupby(['Sku','Value'])['Store'].apply(list).reset_index()
Answered By: stefan_aus_hannover
Categories: questions Tags: , ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.