Complete the code to cast the column 'age' to IntegerType.
df = df.withColumn('age', df['age'].cast([1]))
We use IntegerType() to cast the column to integer values.
Complete the code to replace null values in 'salary' column with 0.
df = df.fillna({'salary': [1])We replace nulls in 'salary' with 0 to avoid null errors in calculations.
Fix the error in casting 'price' column to DoubleType.
from pyspark.sql.types import [1] df = df.withColumn('price', df['price'].cast(DoubleType()))
We must import DoubleType to cast to double precision float.
Complete the code to fill null values in 'age' with 0 and 'name' with 'Unknown' using a dictionary.
df = df.fillna({'age': [1], 'name': [2])We use a dictionary in fillna() to specify different replacement values for different columns: 0 for numeric 'age' and 'Unknown' for string 'name'.
Fill all three blanks to conditionally replace nulls in 'salary' with 0 using when and isNull, then cast to DoubleType.
df = df.withColumn('salary_clean', when(df['salary'].[1](), [2]).otherwise(df['salary']).[3](DoubleType()))
Use isNull() to detect nulls, lit(0) as replacement literal, and cast(DoubleType()) to ensure double type.