DatabricksDatabricks
DATABRICKS-CERTIFIED-ASSOCIATE-DEVELOPER-FOR-APACHE-SPARK · Question #31
DATABRICKS-CERTIFIED-ASSOCIATE-DEVELOPER-FOR-APACHE-SPARK Question #31: Real Exam Question with Answer & Explanation
The correct answer is C: storesDF.withColumn("dayOfYear", dayofyear(col("openDate"))). See the full explanation below for the reasoning.
Perform Data Transformations using Spark DataFrame API
Question
Which of the following code blocks returns a DataFrame containing a column dayOfYear, an integer representation of the day of the year from column openDate from DataFrame storesDF? Note that column openDate is of type integer and represents a date in the UNIX epoch format - the number of seconds since midnight on January 1st, 1970. A sample of storesDF is displayed below:
Options
- A(storesDF.withColumn("openTimestamp", col("openDate").cast("Timestamp"))
- BstoresDF.withColumn("dayOfYear", get dayofyear(col("openDate")))
- CstoresDF.withColumn("dayOfYear", dayofyear(col("openDate")))
- D(storesDF.withColumn("openDateFormat", col("openDate").cast("Date"))
- EstoresDF.withColumn("dayOfYear", substr(col("openDate"), 4, 6))
Topics
#Spark DataFrame API#Date and Time Functions#Column Transformations#Epoch Time Handling
Community Discussion
No community discussion yet for this question.