QuestionQ39

VerifiedPrepare data

You are building a solution by using a Fabric notebook.

You have a Spark DataFrame assigned to a variable named df. The DataFrame returns four columns.

You need to convert the data type of a string column named Age to integer. The solution must return a DataFrame that includes all columns.

How should you complete the code? Each value can be used once, more than once, or not at all.

Drag & Drop
df.("age", ("age").("int")).show()
Explanation

withColumn adds a new column or replaces an existing one while retaining the other columns. col("age") references the existing column, and cast("int") changes its data type to integer.

Learn more

Community Discussion

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