pyspark.sql.functions.mean

pyspark.sql.functions.mean(col: ColumnOrName) → pyspark.sql.column.Column[source]

Aggregate function: returns the average of the values in a group. An alias of avg().

New in version 1.4.0.

Changed in version 3.4.0: Supports Spark Connect.

Parameters
colColumn or str

target column to compute on.

Returns
Column

the column for computed results.

Examples

>>> df = spark.range(10)
>>> df.select(mean(df.id)).show()
+-------+
|avg(id)|
+-------+
|    4.5|
+-------+