Skip to main content
PYSPARK • LESSON 31

Column Arithmetic Calculations

How do we calculate gross revenue by multiplying quantity and unit price using Column arithmetic?

Beginner2 Minutes200 XP
🤔 THE QUESTION

How do we calculate gross revenue by multiplying quantity and unit price using Column arithmetic?

💡 WHAT IS IT?

Applying arithmetic operators (*, +, -, /) directly between Column objects and aliasing the result.

🎯 WHAT IS IT USED FOR?

Calculating order line item totals, discounts, shipping fees, and tax amounts in transaction pipelines.

💻 EXAMPLE
from pyspark.sql.functions import col

df.select(
    col("product_id"),
    (col("unit_price") * col("quantity")).alias("gross_revenue")
).show()

🎯 Mission Objectives

Practice typing production-grade PySpark code for Column Arithmetic Calculations.

  • Multiply Column objects
  • Alias the calculated gross revenue
  • Display sales calculation results