-2

enter image description here

I have a raw data like this and I want to create a new transaction data frame group by customer_id like this enter image description here

How should I do in python? Pleaseeeee~

nisawaras
  • 15
  • 3

1 Answers1

0

nisawaras, welcome to community (in the future the questions should be more precise)

groupby - more info


    data = {'customer_id': [1,1,2 ], 'menu_id': ['Cake','Water','Candy']}
    df = pd.DataFrame(data)
    grouped = df.groupby(['customer_id'])['menu_id'].apply(', '.join).reset_index()
    grouped

output:

enter image description here

Piotr Żak
  • 2,046
  • 5
  • 18
  • 30