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.

Changed in version 3.4.0: Supports Spark Connect.

Parameters
colstr, Column

column containing values to be multiplied together

Returns
Column

the column for computed results.

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|
+----+-------+