pyspark.sql.functions.product

pyspark.sql.functions.product(col)[source]

Aggregate function: returns the product of the values in a group.

New in version 3.2.0.

Parameters
colstr, Column

column containing values to be multiplied together

Examples

>>> df = spark.range(1, 10).toDF('x').withColumn('mod3', col('x') % 3)
>>> prods = df.groupBy('mod3').agg(product('x').alias('product'))
>>> prods.orderBy('mod3').show()
+----+-------+
|mod3|product|
+----+-------+
|   0|  162.0|
|   1|   28.0|
|   2|   80.0|
+----+-------+