Ultimate access to all questions.
Upgrade Now 🚀
Sign in to unlock AI tutor
You are given a Spark DataFrame 'df' with a categorical column 'category'. Write a code snippet that computes the mode (most frequently occurring value) of the 'category' column using the 'mode' function, and explain the steps involved.
A
from pyspark.sql.functions import mode
result = df.select(mode('category'))
print(A)
B
result = df.groupBy('category').count().orderBy('count', ascending=False).first()[0]
print(B)
C
result = df.category.groupBy().count().orderBy(count(), ascending=False).first()
print(C)
D
result = df.category.agg({'category': 'mode'})
print(D)