QuestionQ147

VerifiedDeveloping Apache Spark™ DataFrame/DataSet API Applications

Which of the following code blocks returns a new DataFrame containing a new column, customerSatisfactionAbs, whose values are the absolute values of the customerSatisfaction column in DataFrame storesDF? Note that customerSatisfactionAbs is not in the original DataFrame storesDF.

Explanation

PySpark DataFrame.withColumn returns a new DataFrame by adding a named column from a Column expression. The abs function computes the absolute value of a column or expression, so abs(col("customerSatisfaction")) creates the required values for the new customerSatisfactionAbs column.

Learn more

Community Discussion

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