How do we count the exact number of distinct customer buyers who placed orders?
countDistinct() calculates the exact number of unique values in a Column across all distributed partitions.
Unique buyer metrics, daily active user counts, and cardinality analysis for indexing.
from pyspark.sql.functions import col, countDistinct
df.select(countDistinct(col("customer_id")).alias("unique_buyers")).show()Practice typing production-grade PySpark code for Unique Cardinality with countDistinct().