Skip to main content
PYSPARK โ€ข LESSON 30

Computed Financial Projections with selectExpr()

How do we calculate monthly average customer spending from annual totals using SQL expressions?

Beginnerโฑ 2 Minutesโญ 190 XP
๐Ÿค” THE QUESTION

How do we calculate monthly average customer spending from annual totals using SQL expressions?

๐Ÿ’ก WHAT IS IT?

Using arithmetic division within selectExpr to derive normalized monthly metrics.

๐ŸŽฏ WHAT IS IT USED FOR?

Customer 360 feature engineering, financial modeling, and billing rate calculations.

๐Ÿ’ป EXAMPLE
df.selectExpr(
    "customer_id",
    "total_spend",
    "total_spend / 12 AS monthly_avg_spend"
).show()

๐ŸŽฏ Mission Objectives

Practice typing production-grade PySpark code for Computed Financial Projections with selectExpr().

  • โœ“ Execute division expression in selectExpr
  • โœ“ Alias calculated monthly metric
  • โœ“ Display financial projection