avg

avg #

pyspark.sql.functions.avg(col) #

version: since 1.3

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

avg

Runnable Code:

from pyspark.sql import functions as F
# Set up dataframe
data = [{"num": 1.0},{"num": .5},{"num": 0.0}]
df = spark.createDataFrame(data)
# Use function
df = (df
     .withColumn("avg", F.avg("num"))
     )
df.show()
avg(num)
0.5

Usage:

Often used aggregation function.



returns: \_invoke_function_over_column("avg", col)

PySpark manual

tags: average value, median, mean, average price




© 2023 PySpark Is Rad