Exam Certified Associate Developer for Apache Spark All QuestionsBrowse all questions from this exam
Question 122

Which of the following code blocks returns a new DataFrame with a new column customerSatisfactionAbs that is the absolute value of column customerSatisfaction in DataFrame storesDF? Note that column customerSatisfactionAbs is not in the original DataFrame storesDF.

    Correct Answer: A

    The correct code block to return a new DataFrame with a new column customerSatisfactionAbs containing the absolute value of the column customerSatisfaction in DataFrame storesDF is storesDF.withColumn('customerSatisfactionAbs', abs(col('customerSatisfaction'))). The withColumn method is used to add a new column or replace the existing column in the DataFrame. The col function is used to select the column customerSatisfaction, and the abs function is used to calculate the absolute value.

Discussion
cookiemonster42Option: A

it works for A and E: pyspark.sql.functions.abs(col: ColumnOrName) → pyspark.sql.column.Column[source] Computes the absolute value. New in version 1.3.0. Changed in version 3.4.0: Supports Spark Connect. Parameters colColumn or str target column to compute on.

Sowwy1Option: A

A is correct