
Answer-first summary for fast verification
Answer: storesDF.select(), storesDF.drop()
The question asks for operations that return a new DataFrame excluding specified columns by name. - **Option B (select())**: By selecting all columns except the ones to exclude, `select()` can achieve this. For example, `storesDF.select([col for col in storesDF.columns if col not in columns_to_drop])` excludes specified columns. - **Option C (drop())**: Directly removes specified columns by name, e.g., `storesDF.drop('col1', 'col2')`. - **Other options**: `filter()` (A) affects rows, not columns. `subset()` (D) is not a valid DataFrame method. `dropColumn()` (E) does not exist in Spark; the correct method is `drop()`.
Author: LeetQuiz Editorial Team
Ultimate access to all questions.
No comments yet.
Which of the following operations can be used to create a new DataFrame from DataFrame storesDF by excluding columns specified by name?
A
storesDF.filter()
B
storesDF.select()
C
storesDF.drop()
D
storesDF.subset()
E
storesDF.dropColumn()