Which of the following code blocks creates a new one-column, two-row DataFrame dfDates with column date of type timestamp?
This Question: requires a lot of thinking to get right. For solving it, you may take advantage of the digital notepad that is provided to you during the test. You have probably seen that the code
block
includes multiple errors. In the test, you are usually confronted with a code block that only contains a single error. However, since you are practicing here, this challenging multi-error QUESTION
NO: will
make it easier for you to deal with single-error questions in the real exam.
You can clearly see that column transactionDate should be dropped only after transactionTimestamp has been written. This is because to generate column transactionTimestamp, Spark needs to
read the values from column transactionDate.
Values in column transactionDate in the original transactionsDf DataFrame look like 2020-04-26 15:35. So, to convert those correctly, you would have to pass yyyy-MM-dd HH:mm. In other words:
The string indicating the date format should be adjusted.
While you might be tempted to change unix_timestamp() to to_unixtime() (in line with the from_unixtime() operator), this function does not exist in Spark. unix_timestamp() is the correct operator to
use here.
Also, there is no DataFrame.withColumnReplaced() operator. A similar operator that exists is DataFrame.withColumnRenamed().
Whether you use col() or not is irrelevant with unix_timestamp() - the command is fine with both.
Finally, you cannot assign a column like transactionsDf['columnName'] = ... in Spark. This is Pandas syntax (Pandas is a popular Python package for data analysis), but it is not supported in Spark.
So, you need to use Spark's DataFrame.withColumn() syntax instead.
More info: pyspark.sql.functions.unix_timestamp --- PySpark 3.1.2 documentation
Static notebook | Dynamic notebook: See test 3, Question: 28 (Databricks import instructions)
Roselle
2 months agoAlease
12 days agoZena
20 days agoLeslie
22 days agoHillary
27 days agoTheron
29 days agoJackie
1 months agoRemona
2 months agoTerry
2 months agoFredric
3 months agoCassi
3 months agoKarl
1 months agoVicki
1 months agoAnastacia
1 months agoChan
1 months agoAnastacia
1 months agoLauna
2 months agoErick
3 months agoPaola
3 months agoLezlie
3 months ago