QuestionQ293

VerifiedDeveloping Apache Spark™ DataFrame/DataSet API Applications

Which code block returns a DataFrame with a month column containing the integer month derived from the openDate column in the storesDF DataFrame?

The openDate column is an integer that represents a UNIX epoch date—the number of seconds since midnight on January 1st, 1970.

A sample of storesDF is shown below:

Question Image

Explanation

A Unix-epoch integer expressed in seconds must be converted to a timestamp before its calendar month can be extracted. Casting openDate to Timestamp creates a timestamp column, and Spark’s month function returns the month portion of a date or timestamp as an integer. PySpark Column.cast and PySpark month document these operations.

Learn more

Community Discussion

No comments yet. Be the first to start the discussion!