The code block displayed below contains an error. The code block should return a copy of DataFrame transactionsDf where the name of column transactionId has been changed to
transactionNumber. Find the error.
Code block:
transactionsDf.withColumn("transactionNumber", "transactionId")
A . The arguments to the withColumn method need to be reordered.
B . The arguments to the withColumn method need to be reordered and the copy() operator should be appended to the code block to ensure a copy is returned.
C . The copy() operator should be appended to the code block to ensure a copy is returned.
D . Each column name needs to be wrapped in the col() method and method withColumn should be replaced by method withColumnRenamed.
E . The method withColumn should be replaced by method withColumnRenamed and the arguments to the method need to be reordered.
Answer: E
Explanation:
Correct code block:
transactionsDf.withColumnRenamed("transactionId", "transactionNumber")
Note that in Spark, a copy is returned by default. So, there is no need to append copy() to the code block.
More info: pyspark.sql.DataFrame.withColumnRenamed ― PySpark 3.1.2 documentation Static notebook | Dynamic notebook: See test 2,
Latest Databricks Certified Associate Developer for Apache Spark 3.0 Dumps Valid Version with 180 Q&As
Latest And Valid Q&A | Instant Download | Once Fail, Full Refund