Complete the code to convert the 'name' column to lowercase using Spark string functions.
from pyspark.sql.functions import [1] df_lower = df.select([1]("name").alias("name_lower"))
The lower function converts all characters in a string column to lowercase.
Complete the code to remove spaces from the start and end of the 'city' column.
from pyspark.sql.functions import [1] df_trimmed = df.select([1]("city").alias("city_trimmed"))
The trim function removes leading and trailing spaces from string columns.
Fix the error in the code to extract the first 3 characters from the 'code' column.
from pyspark.sql.functions import substring df_sub = df.select(substring("code", [1], 3).alias("code_sub"))
The substring function in Spark starts counting positions at 1, so to get the first 3 characters, start at position 1.
Fill both blanks to create a dictionary with words as keys and their lengths as values, only for words longer than 4 characters.
words = ["apple", "bat", "carrot", "dog"] lengths = { [1] : len([1]) for [1] in words if len([1]) [2] 4 }
We use word as the variable name and filter words with length greater than 4 using >.
Fill all three blanks to create a dictionary with uppercase words as keys and their lengths as values, only for words containing the letter 'a'.
words = ["apple", "bat", "carrot", "dog"] result = { [1] : [2] for [3] in words if 'a' in [3] }
We use word as the loop variable, convert it to uppercase for keys with word.upper(), and get lengths with len(word).