DATABRICKS-CERTIFIED-ASSOCIATE-DEVELOPER-FOR-APACHE-SPARK-3-0 practice question 15 of 25
In which order should the code blocks shown below be run in order to create a DataFrame that shows the mean of column predError of DataFrame…
Full set: 180 questionsCorrect code block: transactionsDf.filter(transactionsDf.storeId.isNotNull()).groupBy("storeId").pivot("productId", [2, 3]).mean("predError").orderBy("storeId") Output of correct code block: +-------+----+----+ |storeId| 2| 3| +-------+----+----+ | 2| 6.0|null| | 3|null|null| | 25| 3.0| 3.0| +-------+----+----+ This Question: is quite convoluted and requires you to think hard about the correct order of operations. The pivot method also makes an appearance - a method that you may not know all that much about (yet). At the first position in all answers is code block 4, so the Question: is essentially just about the ordering of the remaining 4 code blocks. The Question: states that the returned DataFrame should be sorted by column storeId. So, it should make sense to have code block 3 which includes the orderBy operator at the very end of the code block. This leaves you with only two answer options. Now, it is useful to know more about the context of pivot in PySpark. A common pattern is groupBy, pivot, and then another aggregating function, like mean. In the documentation linked below you can see that pivot is a method of pyspark.sql.GroupedData - meaning that before pivoting, you have to use groupBy. The only answer option matching this requirement is the one in which code block 2 (which includes groupBy) is stated before code block 5 (which includes pivot). More info: pyspark.sql.GroupedData.pivot — PySpark 3.1.2 documentation Static notebook | Dynamic notebook: See test 3,
Keep practicing
Take the free DATABRICKS-CERTIFIED-ASSOCIATE-DEVELOPER-FOR-APACHE-SPARK-3-0 practice test
Ten exam-style questions with answers and explanations, plus the exam facts and study guides.
More questions
Other DATABRICKS-CERTIFIED-ASSOCIATE-DEVELOPER-FOR-APACHE-SPARK-3-0 practice questions
- Question 1The code block displayed below contains an error. The code block is intended to perform a…
- Question 2Which of the following code blocks shows the structure of a DataFrame in a tree-like way,…
- Question 3Which of the following code blocks reads the parquet file stored at filePath into DataFra…
- Question 4Which of the following code blocks returns a 2-column DataFrame that shows the distinct v…
- Question 5The code block shown below should return an exact copy of DataFrame transactionsDf that d…
- Question 6The code block displayed below contains an error. The code block should configure Spark t…
