0
0
Apache Sparkdata~10 mins

Why DataFrames are preferred over RDDs in Apache Spark - Test Your Understanding

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to create a DataFrame from a list of tuples.

Apache Spark
df = spark.createDataFrame([1], ['name', 'age'])
Drag options to blanks, or click blank then click option'
A[('Alice', 34), ('Bob', 45)]
B('Alice', 34, 'Bob', 45)
C['Alice', 34, 'Bob', 45]
D{'Alice': 34, 'Bob': 45}
Attempts:
3 left
💡 Hint
Common Mistakes
Using a dictionary instead of a list of tuples.
Passing a flat list instead of tuples.
2fill in blank
medium

Complete the code to select the 'age' column from the DataFrame.

Apache Spark
ages = df.select([1])
Drag options to blanks, or click blank then click option'
A'name'
B'age'
Cage
Ddf.age
Attempts:
3 left
💡 Hint
Common Mistakes
Using the column variable without quotes.
Selecting the wrong column name.
3fill in blank
hard

Fix the error in the code to filter rows where age is greater than 30.

Apache Spark
filtered = df.filter(df.age [1] 30)
Drag options to blanks, or click blank then click option'
A<
B==
C=
D>
Attempts:
3 left
💡 Hint
Common Mistakes
Using '=' instead of '>' in filter.
Using '==' which may not work as expected in Spark filters.
4fill in blank
hard

Fill both blanks to create a dictionary comprehension that maps each word to its length if length is greater than 3.

Apache Spark
{word: [1] for word in words if [2]
Drag options to blanks, or click blank then click option'
Alen(word)
Blen(word) > 3
Cword
Dword > 3
Attempts:
3 left
💡 Hint
Common Mistakes
Using the word itself instead of its length.
Incorrect condition like word > 3.
5fill in blank
hard

Fill all three blanks to create a dictionary comprehension that maps uppercase words to their lengths if length is greater than 4.

Apache Spark
{ [1]: [2] for word in words if [3] }
Drag options to blanks, or click blank then click option'
Aword.upper()
Blen(word)
Clen(word) > 4
Dword.lower()
Attempts:
3 left
💡 Hint
Common Mistakes
Using word.lower() instead of upper.
Incorrect filter condition.
Swapping keys and values.