QuestionQ295

VerifiedDeveloping Apache Spark™ DataFrame/DataSet API Applications

A developer is analyzing a dataframe, df_epoch_time, with an epoch_time column that contains Unix epoch time. Unix epoch time is a timestamp measured in seconds since January 1, 1970, 00:00:00 UTC. The developer needs to extract the month from this column and add it as a new column named month.

Which code block meets this requirement?

Explanation

PySpark from_unixtime converts seconds since the Unix epoch into a datetime representation, and month extracts that datetime’s month as an integer. Therefore, nesting from_unixtime("epoch_time") inside month produces the required month column. PySpark from_unixtime documentation PySpark month documentation

Learn more

Community Discussion

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