I'm trying to 'merge' the item section into a list according to the Transaction ID. So, I want Chocolate Quente and Jam on a list.
Can you try the following: item_list=df[df["Transaction"]==3]["Item"].to_list()
or list(df[df["Transaction"]==3]["Item"]
I suppose this should work if 3 is an int type. If it's an object (string), use double quotes "3".
df.groupby('Transaction')['Item'].apply(list).reset_index()
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.