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)