DATABRICKS-CERTIFIED-ASSOCIATE-DEVELOPER-FOR-APACHE-SPARK · Question #180
Which of the following code blocks returns a DataFrame where rows in DataFrame storesDF containing missing values in every column have been dropped?
The correct answer is D. storesDF.na.drop("all"). storesDF.na.drop('all') drops only the rows where every column contains a null (missing) value. The 'all' argument means a row is dropped only if all its values are null. Choice A (na.drop() with no arguments) uses the default 'any', which drops rows that have at least one null…
Question
Which of the following code blocks returns a DataFrame where rows in DataFrame storesDF containing missing values in every column have been dropped?
Options
- AstoresDF.na.drop()
- BstoresDF.dropna()
- CstoresDF.na.drop("all", subset = "sqft")
- DstoresDF.na.drop("all")
- EstoresDF.nadrop("all")
How the community answered
(26 responses)- A4% (1)
- B4% (1)
- C4% (1)
- D88% (23)
Explanation
storesDF.na.drop('all') drops only the rows where every column contains a null (missing) value. The 'all' argument means a row is dropped only if all its values are null. Choice A (na.drop() with no arguments) uses the default 'any', which drops rows that have at least one null in any column. Choice B (dropna()) is pandas syntax and is not valid for Spark DataFrames. Choice C applies 'all' but restricts the check to the sqft subset. Choice E uses nadrop() which is not a valid method.
Topics
Community Discussion
No community discussion yet for this question.