snowflake.snowpark.functions.variance¶

snowflake.snowpark.functions.variance(e: Union[Column, str]) → Column[source]¶

Returns the sample variance of non-NULL records in a group. If all records inside a group are NULL, a NULL is returned. For a single row, NULL is returned as sample variance.

Example:

>>> df = session.create_dataframe([1, -1, 1, -1, -1], schema=["a"])
>>> df.select(variance(col("a"))).collect()
[Row(VARIANCE("A")=Decimal('1.200000'))]

>>> df = session.create_dataframe([1, None, 2, 3, None, 5, 6], schema=["a"])
>>> df.select(variance(col("a"))).collect()
[Row(VARIANCE("A")=Decimal('4.300000'))]

>>> df = session.create_dataframe([None, None, None], schema=["a"])
>>> df.select(variance(col("a"))).collect()
[Row(VARIANCE("A")=None)]

>>> df = session.create_dataframe([42], schema=["a"])
>>> df.select(variance(col("a"))).collect()
[Row(VARIANCE("A")=None)]
Copy