Complete the code to select the column 'age' from the DataFrame.
df.select([1]).show()To select a column by name in Spark DataFrame, you pass the column name as a string to select().
Complete the code to create a new column 'age_plus_10' by adding 10 to the 'age' column.
from pyspark.sql.functions import col df = df.withColumn("age_plus_10", [1] + 10)
Use col("age") to refer to the column in expressions.
Fix the error in the code to filter rows where 'score' is greater than 50.
filtered_df = df.filter([1] > 50)
The filter method expects a Column expression. Use col("score") to refer to the column.
Complete the code to create a new column 'high_score' by checking if 'score' > 90.
from pyspark.sql.functions import col, lit df = df.withColumn("high_score", [1]("score") > [2](90))
In Spark DataFrame expressions, reference columns with col() and constants with lit().
Fill all three blanks to create 'new_age' by adding 10 to 'age' only if 'age' > 18, otherwise keep 'age'.
from pyspark.sql.functions import col, lit, when df = df.withColumn("new_age", when([1]("age") [2] 18, [1]("age") + [3](10)).otherwise([1]("age")))
Use when(col("age") > 18, col("age") + lit(10)).otherwise(col("age")) for conditional column creation.