0
0
Apache Sparkdata~10 mins

Select, filter, and where operations in Apache Spark - Interactive Code Practice

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

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

Apache Spark
df.select([1]).show()
Drag options to blanks, or click blank then click option'
A['name']
Bname
C"name"
Ddf.name
Attempts:
3 left
💡 Hint
Common Mistakes
Passing the column name without quotes causes an error.
Using a list instead of a string for a single column.
2fill in blank
medium

Complete the code to filter rows where the 'age' column is greater than 30.

Apache Spark
df.filter(df.age [1] 30).show()
Drag options to blanks, or click blank then click option'
A<
B==
C<=
D>
Attempts:
3 left
💡 Hint
Common Mistakes
Using '<' instead of '>' changes the filter logic.
Using '==' filters only rows with age exactly 30.
3fill in blank
hard

Fix the error in the code to filter rows where 'salary' is less than 50000.

Apache Spark
df.where(df.salary [1] 50000).show()
Drag options to blanks, or click blank then click option'
A>=
B<
C==
D>
Attempts:
3 left
💡 Hint
Common Mistakes
Using '>' filters salaries greater than 50000, which is incorrect.
Using '==' filters only salaries exactly 50000.
4fill in blank
hard

Fill both blanks to create a dictionary comprehension that maps words to their lengths for words longer than 3 characters.

Apache Spark
lengths = {word: [1] for word in words if len(word) [2] 3}
Drag options to blanks, or click blank then click option'
Alen(word)
B<=
C>
Dword
Attempts:
3 left
💡 Hint
Common Mistakes
Using the word itself as the value instead of its length.
Using '<=' instead of '>' in the filter condition.
5fill in blank
hard

Fill all three blanks to create a dictionary comprehension that maps uppercase words to their values for values greater than 0.

Apache Spark
result = { [1]: [2] for k, v in data.items() if v [3] 0 }
Drag options to blanks, or click blank then click option'
Ak.upper()
Bv
C>
Dk
Attempts:
3 left
💡 Hint
Common Mistakes
Using original keys instead of uppercase keys.
Using '<' or '==' instead of '>' in the filter condition.