Complete the code to create a Spark DataFrame from a list of tuples.
df = spark.createDataFrame([1], ['name', 'age'])
To create a DataFrame, you need a list of tuples representing rows.
Complete the code to filter rows where age is greater than 25.
filtered_df = df.filter(df.age [1] 25)
The filter condition should select rows with age greater than 25.
Fix the error in the code to select the 'name' column as a list.
names = df.select([1]).rdd.flatMap(lambda x: x).collect()The select method requires the column name as a string.
Fill both blanks to create a dictionary of names and ages for people older than 20.
result = [1].rdd.filter(lambda x: x.[2] > 20).collectAsMap()
Select both 'name' and 'age' columns, then filter by 'age' attribute in lambda.
Fill all three blanks to create a unit test that checks if the filtered DataFrame has the expected count.
def test_filter_count(): filtered = df.filter(df.[1] [2] [3]) assert filtered.count() == 1
The test filters rows where age is greater than 25 and asserts the count is 1.
