
Answer-first summary for fast verification
Answer: df.select(count(col('age'))).collect()[0][0]
The correct answer is B because it correctly uses the 'count' function with the column name specified as a column object to count the number of non-NULL values in the 'age' column. The 'collect()[0][0]' part retrieves the count value from the resulting DataFrame.
Author: LeetQuiz Editorial Team
Ultimate access to all questions.
Given a DataFrame df with a column 'age' that contains integer values, including NULLs, how would you use the 'count' function to count the number of non-NULL values in the 'age' column?
A
df.select(count('age')).collect()[0][0]
B
df.select(count(col('age'))).collect()[0][0]
C
df.select(count('age').isNull()).collect()[0][0]
D
df.select(count(col('age').isNull())).collect()[0][0]
No comments yet.