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?

Beginner3 Minutes220 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