Wednesday, October 7, 2020

PySpark - Two ways to use UDF

 Method 1:

put @F.udf('string')  on top of the function


Method 2:

Change python function to an UDF function:

from pyspark.sql.functions import *

from pyspark.sql.types import *

function_udf = udf(function, OutputType())

then use the UDF function in your Spark dataframe.

No comments:

Post a Comment