Skip to main content
PYSPARK โ€ข LESSON 206

Array Transformations with transform()

How can we transform every element inside an array column without exploding the DataFrame rows?

Advancedโฑ 3 Minutesโญ 850 XP
๐Ÿค” THE QUESTION

How can we transform every element inside an array column without exploding the DataFrame rows?

๐Ÿ’ก WHAT IS IT?

The higher-order transform() function applies a lambda expression to each item in an array natively in Catalyst.

๐ŸŽฏ WHAT IS IT USED FOR?

Normalizing, discounting, or formatting nested lists of items without multiplying row volume.

๐Ÿ’ป EXAMPLE
df_discounted = df.withColumn("discounted_prices", transform(col("prices"), lambda x: x * 0.9))

๐ŸŽฏ Mission Objectives

Practice typing production-grade PySpark code for Array Transformations with transform().

  • โœ“ transform() higher-order function
  • โœ“ Lambda expressions in PySpark
  • โœ“ Zero-shuffle array processing