Complete the code to add a new column 'age_plus_one' by adding 1 to the 'age' column.
df = df.withColumn('age_plus_one', df['age'] [1] 1)
We use the '+' operator to add 1 to the 'age' column values.
Complete the code to rename the column 'age_plus_one' to 'age_next_year'.
df = df.withColumnRenamed('age_plus_one', [1])
The second argument in withColumnRenamed is the new column name.
Fix the error in the code to add a new column 'double_age' that doubles the 'age' column values.
df = df.withColumn('double_age', df['age'] [1] 2)
To double the age, multiply by 2 using the '*' operator.
Fill both blanks to add a new column 'age_squared' that squares the 'age' column values.
df = df.withColumn('age_squared', df['age'] [1] [2])
Use the '**' operator to raise to the power of 2, which squares the value.
Fill all three blanks to rename 'age_squared' to 'age_power_two' and add a new column 'age_plus_five' by adding 5 to 'age'.
df = df.withColumnRenamed([1], [2]).withColumn('age_plus_five', df['age'] [3] 5)
First, rename 'age_squared' to 'age_power_two'. Then add 5 to 'age' using '+'.