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?

Beginnerโฑ 2 Minutesโญ 200 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