pyspark.sql.functions.try_avg¶
-
pyspark.sql.functions.
try_avg
(col: ColumnOrName) → pyspark.sql.column.Column[source]¶ Returns the mean calculated from values of a group and the result is null on overflow.
New in version 3.5.0.
- Parameters
- col
Column
or str
- col
Examples
>>> import pyspark.sql.functions as sf >>> spark.createDataFrame( ... [(1982, 15), (1990, 2)], ["birth", "age"] ... ).select(sf.try_avg("age")).show() +------------+ |try_avg(age)| +------------+ | 8.5| +------------+