nerdexam
Databricks

DATABRICKS-CERTIFIED-ASSOCIATE-DEVELOPER-FOR-APACHE-SPARK · Question #49

The code block shown below should return a new DataFrame from DataFrame storesDF where column storeId is of the type string. Choose the response that correctly fills in the numbered blanks within…

The correct answer is A. 1. withColumn. The correct completed code is: storesDF.withColumn('storeId', col('storeId').cast(StringType())). Blank 1 is withColumn (replaces or adds a column), blank 2 is col (creates a Column reference from the existing column), blank 3 is cast (converts the column to a new data type)…

DataFrame Transformations

Question

The code block shown below should return a new DataFrame from DataFrame storesDF where column storeId is of the type string. Choose the response that correctly fills in the numbered blanks within the code block to complete this task. Code block:

storesDF.1("storeId", 2("storeId").3(4)

Options

  • A
    1. withColumn
  • B
    1. withColumn
  • C
    1. newColumn
  • D
    1. withColumn
  • E
    1. withColumn

How the community answered

(38 responses)
  • A
    89% (34)
  • B
    3% (1)
  • D
    5% (2)
  • E
    3% (1)

Explanation

The correct completed code is: storesDF.withColumn('storeId', col('storeId').cast(StringType())). Blank 1 is withColumn (replaces or adds a column), blank 2 is col (creates a Column reference from the existing column), blank 3 is cast (converts the column to a new data type), and blank 4 is StringType() (the Spark SQL type representing a string). withColumn overwrites the storeId column with a cast version of itself. The cast() method accepts either a DataType object like StringType() or a string alias like 'string'.

Topics

#Spark DataFrame API#Column Transformation#Data Type Conversion#PySpark

Community Discussion

No community discussion yet for this question.

Full DATABRICKS-CERTIFIED-ASSOCIATE-DEVELOPER-FOR-APACHE-SPARK Practice