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

Certified Associate Developer for Apache Spark 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.

Show Answer
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

2 comments
Sign in to comment
cookiemonster42Option: A
Aug 2, 2023

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
Apr 9, 2024

A is correct