Skip to content

Instantly share code, notes, and snippets.

@dksifoua
Created October 9, 2019 14:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dksifoua/be03f41146deeb2db6816143df53c8f6 to your computer and use it in GitHub Desktop.
Save dksifoua/be03f41146deeb2db6816143df53c8f6 to your computer and use it in GitHub Desktop.
from pyspark.sql.types import StringType
from pyspark.sql.functions import udf
maturity_udf = udf(lambda age: "adult" if age >=18 else "child", StringType())
df = sqlContext.createDataFrame([{'name': 'Alice', 'age': 1}])
df.withColumn("maturity", maturity_udf(df.age))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment