Say I have a list of customer_id as well as the name of the product they have purchased product_name.
product_list = ['hat','pants','shoes','tie'] in A-Z order
| customer_id | product_name |
|---|---|
| 001 | shoes |
| 001 | tie |
| 001 | hat |
| 002 | shoes |
| 002 | tie |
What is the most efficient way in Pyspark to make a cross sell table so it looks like this?
| hat | pants | shoes | tie | |
|---|---|---|---|---|
| hat | 1 | 0 | 1 | 1 |
| pants | 0 | 0 | 0 | 0 |
| shoes | 1 | 0 | 2 | 2 |
| tie | 1 | 0 | 2 | 2 |
The way to interpret that is reading from the first column: of all the customers who bought a hat this is how many also bought the item in the other columns
So customers who bought a hat also in total bought 1 tie