DATABRICKS-CERTIFIED-ASSOCIATE-DEVELOPER-FOR-APACHE-SPARK · Question #21
The code block shown below contains an error. The code block is intended to print the schema of DataFrame storesDF. Identify the error. Code block: storesDF.printSchema
The correct answer is E. The printSchema member of DataFrame is an operation and needs to be followed by. In PySpark, printSchema is a method on DataFrame, not a property. Writing storesDF.printSchema without parentheses simply references the method object but does not call it-no output is produced. The correct syntax is storesDF.printSchema() with parentheses to invoke the method…
Question
The code block shown below contains an error. The code block is intended to print the schema of DataFrame storesDF. Identify the error. Code block:
storesDF.printSchema
Options
- AThere is no printSchema member of DataFrame - schema and the print() function should be used
- BThe entire line needs to be a string - it should be wrapped by str().
- CThere is no printSchema member of DataFrame - the getSchema() operation should be used
- DThere is no printSchema member of DataFrame - the schema() operation should be used instead.
- EThe printSchema member of DataFrame is an operation and needs to be followed by
How the community answered
(43 responses)- B5% (2)
- C7% (3)
- D2% (1)
- E86% (37)
Explanation
In PySpark, printSchema is a method on DataFrame, not a property. Writing storesDF.printSchema without parentheses simply references the method object but does not call it-no output is produced. The correct syntax is storesDF.printSchema() with parentheses to invoke the method and actually print the schema to the console.
Topics
Community Discussion
No community discussion yet for this question.