categories = df.select('Text').distinct().rdd.flatMap(lambda x: x).collect()
exprs = [F.when(F.col('Text') == category, 1).otherwise(0).alias(category) for
    category in categories]
pyspark matrix with dummy variables