Skip to main content
PYSPARK • LESSON 40

Range Filtering with between()

How do we filter records falling within an inclusive numerical age boundary?

Beginner3 Minutes230 XP
🤔 THE QUESTION

How do we filter records falling within an inclusive numerical age boundary?

💡 WHAT IS IT?

between(lower, upper) checks if a numeric or date column value falls inclusively within the specified range.

🎯 WHAT IS IT USED FOR?

Demographic targeting, credit score tiering, date window filtering, and price bracket analysis.

💻 EXAMPLE
from pyspark.sql.functions import col

df.filter(col("age").between(25, 45)).show()

🎯 Mission Objectives

Practice typing production-grade PySpark code for Range Filtering with between().

  • Use between() for inclusive range checking
  • Filter prime demographic cohort
  • Display bounded age records