
Answer-first summary for fast verification
Answer: df.filter(col('salary').isNull()).count()
The correct answer is A because it correctly uses the 'isNull' method to filter rows where the 'salary' column is NULL and then counts these rows. The '== NULL' syntax is incorrect in PySpark.
Author: LeetQuiz Editorial Team
Ultimate access to all questions.
Given a DataFrame df with columns 'id', 'name', and 'salary', you need to identify how many rows have a NULL value in the 'salary' column. Write the PySpark code to achieve this.
A
df.filter(col('salary').isNull()).count()
B
df.filter(col('salary') == NULL).count()
C
df.filter(col('salary').isNotNull()).count()
D
df.filter(col('salary') != NULL).count()
No comments yet.