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?

Intermediate2 Minutes380 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