Piezīmes
Lai piekļūtu šai lapai, ir nepieciešama autorizācija. Varat mēģināt pierakstīties vai mainīt direktorijus.
Lai piekļūtu šai lapai, ir nepieciešama autorizācija. Varat mēģināt mainīt direktorijus.
Returns the mean calculated from values of a group and the result is null on overflow.
Syntax
from pyspark.sql import functions as sf
sf.try_avg(col)
Parameters
| Parameter | Type | Description |
|---|---|---|
col |
pyspark.sql.Column or column name |
Target column to compute on. |
Examples
Example 1: Calculating the average age
import pyspark.sql.functions as sf
df = spark.createDataFrame([(1982, 15), (1990, 2)], ["birth", "age"])
df.select(sf.try_avg("age")).show()
+------------+
|try_avg(age)|
+------------+
| 8.5|
+------------+
Example 2: Calculating the average age with None
import pyspark.sql.functions as sf
df = spark.createDataFrame([(1982, None), (1990, 2), (2000, 4)], ["birth", "age"])
df.select(sf.try_avg("age")).show()
+------------+
|try_avg(age)|
+------------+
| 3.0|
+------------+