Skip to content

43. Data Quality: Null Count per Column

Difficulty: Medium · Topics: Null Handling, Filtering & Selection

Before loading customers, profile it: return a single row with one column per input column named <column>_nulls, holding how many rows have null in that column.

Write it so it works for any table, without typing column names.

Row order does not matter; column names must match. Your code is graded on 3 test cases, including hidden edge cases.

Sample data

customers

idemailphonecity
1a@x.innullPune
2nullnullGoa
3c@x.in99null

Expected output

id_nullsemail_nullsphone_nullscity_nulls
0121

Hints

Hint 1customers.columns is a Python list of names.
Hint 2Build the expressions with a list comprehension and pass the list to select.
Hint 3F.sum(F.col(c).isNull().cast("int")) counts nulls in column c.

PySpark functions you'll practise

Related problems

Browse

Topics: Window Functions · Joins · Aggregations · Pivot, Unpivot & Rollup · Arrays · Null Handling · Conditional Logic · Dates · Filtering & Selection · Strings

Difficulty: Easy · Medium · Hard · PySpark interview roadmap · All problems