pyspark.sql.functions.
count_distinct
Returns a new Column for distinct count of col or cols.
Column
col
cols
New in version 3.2.0.
Examples
>>> df.agg(count_distinct(df.age, df.name).alias('c')).collect() [Row(c=2)]
>>> df.agg(count_distinct("age", "name").alias('c')).collect() [Row(c=2)]