QuestionQ133

VerifiedDeveloping Apache Spark™ DataFrame/DataSet API Applications

The code block below must create a Python UDF, assessPerformanceUDF, using the Python function assessPerformance() and apply it to the customerSatisfaction column in the storesDF DataFrame. Choose the response that correctly completes the numbered blanks in the code block to perform this task.

assessPerformanceUDF = _1_(_2_)  
storesDF.withColumn(“result”, _3_(_4_))  
Explanation

pyspark.sql.functions.udf creates a Python UDF from a Python function and an optional return type; specifying IntegerType() defines the UDF result as an integer. Invoking the resulting UDF with col("customerSatisfaction") produces the Column expression required by DataFrame.withColumn to add result.

Learn more

Community Discussion

No comments yet. Be the first to start the discussion!