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?

Beginner2 Minutes190 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