QuestionQ26

VerifiedDeveloping Apache Spark™ DataFrame/DataSet API Applications

A data analyst is working with a DataFrame called dates_df and must add a new column, date, derived from the timestamp field.

Which code fragment should be used to extract the date from a timestamp?

Explanation

pyspark.sql.functions.to_date converts a column to Spark DateType; when applied to a timestamp column, it returns the calendar-date portion. This makes it appropriate for creating a date column from timestamp.

Learn more

Community Discussion

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