pyspark.sql.functions.
approx_count_distinct
Aggregate function: returns a new Column for approximate distinct count of column col.
Column
New in version 2.1.0.
Changed in version 3.4.0: Supports Spark Connect.
maximum relative standard deviation allowed (default = 0.05). For rsd < 0.01, it is more efficient to use count_distinct()
count_distinct()
the column of computed results.
Examples
>>> df = spark.createDataFrame([1,2,2,3], "INT") >>> df.agg(approx_count_distinct("value").alias('distinct_values')).show() +---------------+ |distinct_values| +---------------+ | 3| +---------------+