Pandas Finding Cross Sell In Two Columns In A Data Frame
What I'm trying to do is a kind of a cross sell. I have a Pandas dataframe with two columns, one with receipt numbers, and the other with product ids: receipt product 1 a 1
Solution 1:
I think this is what you looking for
df.groupby(['receipt']).agg({'product': list}).assign(count=lambda x: x['product'].str.len())
product count
receipt
1[a, b]22[c]13[b, a]2
Post a Comment for "Pandas Finding Cross Sell In Two Columns In A Data Frame"