I'm trying to find the count of combinations of products inside receipts in Pandas. Thru some help I was able to find the combination of two products in a previous question, but I still have doubts of how to achieve this result, and how I could escalate it to find more combinations.
I have two columns in the data frame, one of receipts and the other of products that were bought:
receipt_id product_name
1 apple
1 bread
1 cola
2 apple
2 cola
2 bread
3 apple
3 cola
4 apple
4 cola
4 bread
I'd like to find the count of combinations of 3 products inside the receipts. So, for this example, the result should be something like this:
product1 product2 product3 count
apple bread cola 3
Which means: this first combination of products appears in 3 receipts. The count of 'apple' and 'cola' does not appear, as it was a combination of just two products.
I know I need to use the groupby function, but now sure of how to organize data inside the same column. Any help is aprecciated! Thanks in advance.