Deal of The Day! Hurry Up, Grab the Special Discount - Save 25% - Ends In 00:00:00 Coupon code: SAVE25
Welcome to Pass4Success

- Free Preparation Discussions

Databricks Exam Databricks-Certified-Associate-Developer-for-Apache-Spark-3.0 Topic 2 Question 62 Discussion

Actual exam question for Databricks's Databricks Certified Associate Developer for Apache Spark 3.0 exam
Question #: 62
Topic #: 2
[All Databricks Certified Associate Developer for Apache Spark 3.0 Questions]

The code block shown below should return a copy of DataFrame transactionsDf with an added column cos. This column should have the values in column value converted to degrees and having

the cosine of those converted values taken, rounded to two decimals. Choose the answer that correctly fills the blanks in the code block to accomplish this.

Code block:

transactionsDf.__1__(__2__, round(__3__(__4__(__5__)),2))

Show Suggested Answer Hide Answer
Suggested Answer: C

Correct code block:

transactionsDf.withColumn('cos', round(cos(degrees(transactionsDf.value)),2))

This Question: is especially confusing because col, 'cos' are so similar. Similar-looking answer options can also appear in the exam and, just like in this question, you need to pay attention to

the

details to identify what the correct answer option is.

The first answer option to throw out is the one that starts with withColumnRenamed: The Question: speaks specifically of adding a column. The withColumnRenamed operator only renames

an

existing column, however, so you cannot use it here.

Next, you will have to decide what should be in gap 2, the first argument of transactionsDf.withColumn(). Looking at the documentation (linked below), you can find out that the first argument of

withColumn actually needs to be a string with the name of the column to be added. So, any answer that includes col('cos') as the option for gap 2 can be disregarded.

This leaves you with two possible answers. The real difference between these two answers is where the cos and degree methods are, either in gaps 3 and 4, or vice-versa. From the QUESTION

NO: you

can find out that the new column should have 'the values in column value converted to degrees and having the cosine of those converted values taken'. This prescribes you a clear order of

operations: First, you convert values from column value to degrees and then you take the cosine of those values. So, the inner parenthesis (gap 4) should contain the degree method and then,

logically, gap 3 holds the cos method. This leaves you with just one possible correct answer.

More info: pyspark.sql.DataFrame.withColumn --- PySpark 3.1.2 documentation

Static notebook | Dynamic notebook: See test 3, Question: 49 (Databricks import instructions)


Contribute your Thoughts:

Eveline
1 months ago
Ha! 'degrees' and 'cos' in the same code block? Sounds like the examiners are trying to trick us with a little trigonometry humor. But Option C is the way to go.
upvoted 0 times
Chauncey
19 days ago
Let's go with Option C then.
upvoted 0 times
...
Truman
23 days ago
Yeah, I agree. It's definitely Option C.
upvoted 0 times
...
Stefany
1 months ago
I think Option C is correct.
upvoted 0 times
...
...
Glory
2 months ago
I believe option A is the best choice because it uses the correct syntax for withColumn and col.
upvoted 0 times
...
Lashaunda
2 months ago
I agree with Holley, Option C is the correct answer. The code looks straightforward and should do what the question is asking.
upvoted 0 times
Veda
1 months ago
Let's go with Option C then.
upvoted 0 times
...
Ma
1 months ago
I agree with you, Option C seems to be the most logical.
upvoted 0 times
...
Georgeanna
1 months ago
I'm not sure, I think Option A might be the right choice.
upvoted 0 times
...
Catalina
1 months ago
I think Option C is correct too.
upvoted 0 times
...
...
Carissa
2 months ago
I'm not sure, but I think option C could also work.
upvoted 0 times
...
Jerry
2 months ago
I agree with Felix, option A seems to be the right choice.
upvoted 0 times
...
Felix
2 months ago
I think the correct answer is A.
upvoted 0 times
...
Holley
2 months ago
Option C looks good to me. The code block uses the withColumn method to add a new column 'cos' to the DataFrame, and it applies the cos function to the degrees of the 'value' column.
upvoted 0 times
Merilyn
1 months ago
So, option C is the right choice.
upvoted 0 times
...
Merilyn
1 months ago
It also applies the cos function to the degrees of the 'value' column.
upvoted 0 times
...
Merilyn
2 months ago
Yes, option C uses the withColumn method to add the 'cos' column.
upvoted 0 times
...
Merilyn
2 months ago
I think option C is correct.
upvoted 0 times
...
...

Save Cancel