QuestionQ283

VerifiedDeveloping Apache Spark™ DataFrame/DataSet API Applications

The code block below contains an error. It is intended to return a new DataFrame from DataFrame storesDF in which column storeId has the type string. Identify the error.

Code block:

storesDF.withColumn(“storeId”, cast(col(“storeId”), StringType()))  
Explanation

PySpark performs a type conversion by calling cast on a Column, such as col("storeId").cast(StringType()). withColumn can replace a same-named existing column, and StringType() is a valid cast target. pyspark.sql.Column.cast

Learn more

Community Discussion

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