I want to join data from a dataframe by customer id (Python)

Question:

I have a dataframe (pandas python) in this format:

ID Valor
1 15
1 10
1 25
2 13
3 10
3 11

What I want to do is join the data by id into a list so that it looks like this:

ID Valor
1 [15,10,25]
2 13
3 [10,11]

Someone can help me, please?

Answers:

Use:

df2 = df.groupby('ID', as_index = False)['Valor'].agg(list)
Answered By: user19077881
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.