DATABRICKS-CERTIFIED-ASSOCIATE-DEVELOPER-FOR-APACHE-SPARK · Question #11
Which of the following operations fails to return a DataFrame with no duplicate rows?
The correct answer is E. DataFrame.drop_duplicates(subset = "all"). In PySpark, dropDuplicates() and its alias drop_duplicates() accept an optional subset parameter that takes either None (meaning all columns) or a list of column names. Passing subset=None explicitly is valid and means 'consider all columns,' which is identical to calling the…
Question
Which of the following operations fails to return a DataFrame with no duplicate rows?
Options
- ADataFrame.dropDuplicates()
- BDataFrame.distinct()
- CDataFrame.drop_duplicates()
- DDataFrame.drop_duplicates(subset = None)
- EDataFrame.drop_duplicates(subset = "all")
How the community answered
(29 responses)- A3% (1)
- C3% (1)
- E93% (27)
Explanation
In PySpark, dropDuplicates() and its alias drop_duplicates() accept an optional subset parameter that takes either None (meaning all columns) or a list of column names. Passing subset=None explicitly is valid and means 'consider all columns,' which is identical to calling the method with no arguments. However, subset="all" is not a valid argument - the string "all" is not recognized as a special keyword and is not a column name, so this call raises an AnalysisException or behaves unexpectedly. Options A, B, C, and D all correctly remove duplicate rows; only E fails.
Topics
Community Discussion
No community discussion yet for this question.