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

Time:01-05

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?

CodePudding user response:

Use:

df2 = df.groupby('ID', as_index = False)['Valor'].agg(list)
  • Related