Exam Certified Associate Developer for Apache Spark All QuestionsBrowse all questions from this exam
Question 154

Which of the following code blocks fails to return the number of rows in DataFrame storesDF for each distinct combination of values in column division and column storeCategory?

    Correct Answer: B

    The code block that fails to return the number of rows in DataFrame storesDF for each distinct combination of values in column division and column storeCategory is the one that attempts to group by column division and then tries to group by storeCategory on an already grouped DataFrame. This results in an error since 'GroupedData' object doesn't have a groupBy method. Therefore, the correct option is storesDF.groupBy('division').groupBy('storeCategory').count().

Discussion
SaiPavan10Option: B

B is the right choice. I tested with my dataframe option B threw this error AttributeError: 'GroupedData' object has no attribute 'groupBy'

YiJiaSuOption: D

D is correct !

Ahlo

it is possible to run in pyspark - storesDF.groupBy("division", "storeCategory").count() Correct answer is B