I have a dataframe that is sturctured like below, but with 300 different products and about 20.000 orders.
| Order | Avocado | Mango | Chili |
|---|---|---|---|
| 1546 | 500 | 20 | 0 |
| 861153 | 200 | 500 | 5 |
| 1657446 | 500 | 20 | 0 |
| 79854 | 200 | 500 | 1 |
| 4654 | 500 | 20 | 0 |
| 74654 | 0 | 500 | 800 |
I found out what combinations are often together with this code (abbrivated here to 3 products).
size = df.groupby(['AVOCADO', 'MANGO', 'CHILI'], as_index=False).size().sort_values(by=['size'], ascending=False)
Now I want to know per product how often it is bought solo and how often with other products.
Something like this would be my ideal output (fictional numbers) where the percentage shows what percentage of total orders with that product had the other products as well:
| Product | Avocado | Mango | Chili |
|---|---|---|---|
| AVOCADO | 100% | 20 % | 1% |
| MANGO | 20 % | 100% | 3% |
| CHILI | 20% | 30% | 100% |