Skip to main content
PYSPARK • LESSON 43

Arithmetic Column Subtraction

How do we calculate net transaction amount after subtracting promotional discounts?

Intermediate2 Minutes270 XP
🤔 THE QUESTION

How do we calculate net transaction amount after subtracting promotional discounts?

💡 WHAT IS IT?

Performing element-wise arithmetic subtraction between two numeric columns using Column operators.

🎯 WHAT IS IT USED FOR?

Revenue reconciliation, invoice processing, and financial balance sheet calculations.

💻 EXAMPLE
from pyspark.sql.functions import col

df = df.withColumn("net_amount", col("gross_amount") - col("discount"))

🎯 Mission Objectives

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

  • Subtract numeric Column values
  • Store result in new column
  • Calculate net financial totals