pyspark.sql.functions.regr_count#

pyspark.sql.functions.regr_count(y, x)[source]#

Aggregate function: returns the number of non-null number pairs in a group, where y is the dependent variable and x is the independent variable.

New in version 3.5.0.

Parameters
yColumn or str

the dependent variable.

xColumn or str

the independent variable.

Returns
Column

the number of non-null number pairs in a group.

Examples

>>> from pyspark.sql import functions as sf
>>> x = (sf.col("id") % 3).alias("x")
>>> y = (sf.randn(42) + x * 10).alias("y")
>>> spark.range(0, 1000, 1, 1).select(x, y).select(
...     sf.regr_count("y", "x"), sf.count(sf.lit(0))
... ).show()
+----------------+--------+
|regr_count(y, x)|count(0)|
+----------------+--------+
|            1000|    1000|
+----------------+--------+