Skip to main content
PYSPARK โ€ข LESSON 32

Selecting Transformed & Rounded Columns

How do we compute effective tax rate from order subtotal and round the result to 4 decimal places?

Beginnerโฑ 3 Minutesโญ 220 XP
๐Ÿค” THE QUESTION

How do we compute effective tax rate from order subtotal and round the result to 4 decimal places?

๐Ÿ’ก WHAT IS IT?

Combining Column division with the built-in round() SQL function inside a select projection.

๐ŸŽฏ WHAT IS IT USED FOR?

Precision accounting calculations, financial reporting, and tax audit compliance pipelines.

๐Ÿ’ป EXAMPLE
from pyspark.sql.functions import col, round

df.select(
    col("order_id"),
    round(col("tax_amount") / col("subtotal"), 4).alias("tax_rate")
).show()

๐ŸŽฏ Mission Objectives

Practice typing production-grade PySpark code for Selecting Transformed & Rounded Columns.

  • โœ“ Import col and round functions
  • โœ“ Calculate and round ratio expression
  • โœ“ Alias and display precision tax rate