Skip to content
Advertisement

How to create a list from dataframe pandas

My dataset contains columns of usersID and itemsID that they have purchased. Each user might have purchased more than 1 item.

I neeed to make a list so that the key will be the userID and the values the itemsID he purchased for example if user_1 has purchased [item_20,item_25,item_32], my dataset contains 3 rows for this user as follows

row_1= 1,20 row_2= 1,25 row_3= 1,32

I want my list to have the fromat {1: [20,25,32]}

I want to creat a list for all the users in my dataset as the example above.

Advertisement

Answer

if I understand correctly you want something like this!

Next time it would help to see what things you have tried

JavaScript
User contributions licensed under: CC BY-SA
3 People found this is helpful
Advertisement