The code block shown below should add column transactionDateForm to DataFrame transactionsDf. The column should express the unix-format timestamps in column transactionDate as string
type like Apr 26 (Sunday). Choose the answer that correctly fills the blanks in the code block to accomplish this.
transactionsDf.__1__(__2__, from_unixtime(__3__, __4__))
Correct code block:
transactionsDf.withColumn('transactionDateForm', from_unixtime('transactionDate', 'MMM d (EEEE)'))
The Question: specifically asks about 'adding' a column. In the context of all presented answers, DataFrame.withColumn() is the correct command for this. In theory, DataFrame.select() could
also be
used for this purpose, if all existing columns are selected and a new one is added. DataFrame.withColumnRenamed() is not the appropriate command, since it can only rename existing columns, but
cannot add a new column or change the value of a column.
Once DataFrame.withColumn() is chosen, you can read in the documentation (see below) that the first input argument to the method should be the column name of the new column.
The final difficulty is the date format. The Question: indicates that the date format Apr 26 (Sunday) is desired. The answers give 'MMM d (EEEE)' and 'MM d (EEE)' as options. It can be hard
to
know the details of the date format that is used in Spark. Specifically, knowing the differences between MMM and MM is probably not something you deal with every day. But, there is an easy way
to remember the difference: M (one letter) is usually the shortest form: 4 for April. MM includes padding: 04 for April. MMM (three letters) is the three-letter month abbreviation: Apr for April. And
MMMM is the longest possible form: April. Knowing this four-letter sequence helps you select the correct option here.
More info: pyspark.sql.DataFrame.withColumn --- PySpark 3.1.2 documentation
Static notebook | Dynamic notebook: See test 3, Question: 35 (Databricks import instructions)
Dortha
6 days agoMari
11 months agoNorah
11 months agoCruz
11 months agoLarue
10 months agoJustine
10 months agoMatt
11 months agoElroy
11 months agoJamal
12 months agoFredric
12 months agoAbraham
12 months agoEleonora
11 months agoEdison
11 months agoDion
11 months agoTran
11 months agoDomonique
12 months agoLisha
11 months agoNieves
11 months agoYong
11 months agoEarlean
1 years agoRolland
1 years agoYun
12 months agoLavera
12 months agoMa
12 months agoSalena
1 years agoCiara
1 years agoMargart
1 years agoCarmelina
1 years agoAnnamae
12 months agoPrecious
12 months agoJudy
12 months agoCharlette
12 months ago