Pyspark Matrix Transformation
The way to do this in PySpark is to use groupBy and pivot. Since you don't want to do any actual aggregation, just the pivot, you can use first here.

from pyspark.sql.functions import first

(df.groupBy("Customer")
  .pivot("product")
  .agg(first("rating"))
  .fillna(0))


pivot will give nulls when there is no value so fillna needs to be used as well to give the wanted result.