Independence Day Deal! Unlock 25% OFF Today – Limited-Time Offer - 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 48 Discussion

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

Which of the following code blocks returns DataFrame transactionsDf sorted in descending order by column predError, showing missing values last?

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:

Gracia
1 months ago
I dunno, I'm just hoping the exam doesn't sort me in descending order and leave me last. That would be a real `predError`!
upvoted 0 times
...
Paulina
1 months ago
I think I'll choose B. It's a little more verbose, but I like how it separates the sorting direction from the missing value handling.
upvoted 0 times
...
Elza
1 months ago
I'm gonna go with D. It's short and to the point, and I trust the `desc_nulls_last()` method to do the right thing.
upvoted 0 times
...
Dong
1 months ago
Hmm, I was going to pick B, but now I'm second-guessing myself. Do I really need to worry about missing values in this case?
upvoted 0 times
Raymon
9 days ago
User2: I'm not so sure, maybe we should consider if missing values are important.
upvoted 0 times
...
Susana
17 days ago
User1: I think you should go with option B.
upvoted 0 times
...
...
Vallie
2 months ago
I prefer C. It's more explicit about the sorting direction and feels more Pythonic to me.
upvoted 0 times
Wilda
7 days ago
User3: I'm not sure, but I think A might be the correct answer.
upvoted 0 times
...
Cathrine
8 days ago
User2: I agree with you, B seems like the right choice.
upvoted 0 times
...
Denny
27 days ago
User1: I think B is the correct option.
upvoted 0 times
...
...
Hortencia
2 months ago
B looks the most concise and readable to me. I like how it explicitly sorts in descending order and handles missing values.
upvoted 0 times
...
Tu
2 months ago
I'm not sure, but I think option A might also work because it sorts in ascending order with nulls last.
upvoted 0 times
...
Brock
2 months ago
I agree with Lucina, option B makes sense because it sorts in descending order and shows missing values last.
upvoted 0 times
...
Lucina
2 months ago
I think the correct answer is B) transactionsDf.orderBy(\'predError\').desc_nulls_last().
upvoted 0 times
...
Maira
2 months ago
Why do you think B is the correct answer?
upvoted 0 times
...
Ira
2 months ago
I disagree, I believe the correct answer is B.
upvoted 0 times
...
Maira
3 months ago
I think the answer is C.
upvoted 0 times
...

Save Cancel