exam questions

Exam Certified Associate Developer for Apache Spark All Questions

View all questions & answers for the Certified Associate Developer for Apache Spark exam

Exam Certified Associate Developer for Apache Spark topic 1 question 36 discussion

Which of the following code blocks fails to return a DataFrame reverse sorted alphabetically based on column division?

  • A. storesDF.orderBy("division", ascending – False)
  • B. storesDF.orderBy(["division"], ascending = [0])
  • C. storesDF.orderBy(col("division").asc())
  • D. storesDF.sort("division", ascending – False)
  • E. storesDF.sort(desc("division"))
Show Suggested Answer Hide Answer
Suggested Answer: C 🗳️

Comments

Chosen Answer:
This is a voting comment (?). It is better to Upvote an existing comment if you don't have anything to add.
Switch to a voting comment New
58470e1
2 months, 4 weeks ago
Selected Answer: E
doesn't reverse sorted alphabetically mean descending????
upvoted 1 times
...
jds0
6 months, 3 weeks ago
Selected Answer: C
C is the right answer. See code below with Spark 3.5.1 # Sort a DataFrame by a column in reverse alphabetical order from pyspark.sql import SparkSession from pyspark.sql.functions import col, asc, desc from pyspark.errors import PySparkTypeError spark = SparkSession.builder.appName("MyApp").getOrCreate() data = [ (0, 43161, "A"), (1, 51200, "A"), (2, None, "B"), (3, 78367, "B"), (4, None, "C"), ] storesDF = spark.createDataFrame(data, ["storeID", "sqft", "division"]) storesDF.orderBy("division", ascending = False).show() storesDF.orderBy(["division"], ascending = [0]).show() storesDF.orderBy(col("division").asc()).show() storesDF.sort("division", ascending = False).show() storesDF.sort(desc("division")).show()
upvoted 1 times
...
dbdantas
10 months, 1 week ago
Selected Answer: C
C is the correct answer
upvoted 2 times
...
azurearch
11 months, 1 week ago
C is the right answer because it returns the dataframe in ascending order.
upvoted 2 times
...
mahmoud_salah30
1 year, 1 month ago
b i tesetd ut
upvoted 1 times
...
vishnuas
1 year, 2 months ago
C. It is the only option "not returning" the dataframe in descending(reverse) order. All other formats are returning the descending order. In Oprtion E, if we import the desc function,. it will not throw error and will return the dataframe in descending order.
upvoted 1 times
...
outwalker
1 year, 3 months ago
E. storesDF.sort(desc("division")) Option E correctly uses the desc function to specify the descending order for sorting. Thank you for providing additional information and clarification.
upvoted 1 times
...
singh100
1 year, 6 months ago
Option A and D is giving errors. ~ cannot be used in ascending. Right way is to use ascending=False. Most relevant option is C which is sorting the data in ascending order , Option A, D have some typos it should be = instead of ~.
upvoted 1 times
...
singh100
1 year, 6 months ago
C is the answer. Only C will make the data in ascending order. Tested the code.
upvoted 3 times
...
zozoshanky
1 year, 6 months ago
E is right
upvoted 3 times
...
ItsAB
1 year, 7 months ago
It's C: storesDF.orderBy(col("division").asc()) => storesDF.orderBy(col("division").desc())
upvoted 1 times
...
lakhan0309
1 year, 7 months ago
Option E is right answer
upvoted 2 times
...
Community vote distribution
A (35%)
C (25%)
B (20%)
Other
Most Voted
A voting comment increases the vote count for the chosen answer by one.

Upvoting a comment with a selected answer will also increase the vote count towards that answer by one. So if you see a comment that you already agree with, you can upvote it instead of posting a new comment.

SaveCancel
Loading ...
exam
Someone Bought Contributor Access for:
SY0-701
London, 1 minute ago