Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

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

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?

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

Use:

df2 = df.groupby('ID', as_index = False)['Valor'].agg(list)
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading