Skip to main content
PYSPARK โ€ข LESSON 76

Finding Range Extremes with min() and max()

How do we find the lowest and highest product unit prices in a catalog in a single query?

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

How do we find the lowest and highest product unit prices in a catalog in a single query?

๐Ÿ’ก WHAT IS IT?

min() and max() identify the minimum and maximum values in a Column across distributed partitions.

๐ŸŽฏ WHAT IS IT USED FOR?

Detecting pricing boundaries, identifying latency spikes, and tracking date ranges in event logs.

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

df.select(
    min(col("unit_price")).alias("min_price"),
    max(col("unit_price")).alias("max_price")
).show()

๐ŸŽฏ Mission Objectives

Practice typing production-grade PySpark code for Finding Range Extremes with min() and max().

  • โœ“ Import min and max functions
  • โœ“ Compute pricing boundaries in single pass
  • โœ“ Alias minimum and maximum metrics