Skip to main content
PYSPARK โ€ข LESSON 84

Category Benchmarks with avg()

How do we compute the average product review rating for each merchandise category?

Intermediateโฑ 2 Minutesโญ 410 XP
๐Ÿค” THE QUESTION

How do we compute the average product review rating for each merchandise category?

๐Ÿ’ก WHAT IS IT?

Grouping by product category and applying the avg() aggregate function to rating scores.

๐ŸŽฏ WHAT IS IT USED FOR?

Product catalog benchmarking, merchant quality monitoring, and recommendation engine features.

๐Ÿ’ป EXAMPLE
from pyspark.sql.functions import avg, col

df.groupBy("category").agg(avg(col("rating")).alias("avg_rating")).show()

๐ŸŽฏ Mission Objectives

Practice typing production-grade PySpark code for Category Benchmarks with avg().

  • โœ“ Group by product category
  • โœ“ Calculate mean review rating
  • โœ“ Alias average rating metric