Skip to main content
PYSPARK โ€ข LESSON 71

Automated Data Quality Null Audit

How do we dynamically compute the count of null values across every column in a DataFrame?

Intermediateโฑ 3 Minutesโญ 400 XP
๐Ÿค” THE QUESTION

How do we dynamically compute the count of null values across every column in a DataFrame?

๐Ÿ’ก WHAT IS IT?

Using a Python list comprehension to count null values for each column dynamically in a single select statement.

๐ŸŽฏ WHAT IS IT USED FOR?

Automated pipeline data profiling, ingress data validation gates, and data quality SLA alerts.

๐Ÿ’ป EXAMPLE
from pyspark.sql.functions import col, count, when

df.select([
    count(when(col(c).isNull(), c)).alias(c)
    for c in df.columns
]).show()

๐ŸŽฏ Mission Objectives

Practice typing production-grade PySpark code for Automated Data Quality Null Audit.

  • โœ“ Construct list comprehension over df.columns
  • โœ“ Count nulls with count(when(isNull))
  • โœ“ Display full schema data quality summary