QuestionQ66

VerifiedData Processing & Transformations

A data engineering team is analyzing customer transactions with a PySpark DataFrame named transactions, containing the columns customer_id, amount, and category.

For every customer, the team must calculate the total transaction amount, average transaction amount, and maximum amount—all in one operation for efficiency.

Which PySpark code fragment accomplishes this?

Explanation

groupBy("customer_id").agg(...) performs aggregations separately for every customer, and agg accepts multiple aggregate expressions in the same call. The sum, avg, and max expressions over amount therefore produce the required total, average, and maximum in one grouped operation.

Learn more

Community Discussion

No comments yet. Be the first to start the discussion!