0
0
Apache Sparkdata~10 mins

What is Apache Spark - Interactive Quiz & Practice

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

Complete the code to create a Spark session.

Apache Spark
from pyspark.sql import SparkSession
spark = SparkSession.builder.appName([1]).getOrCreate()
Drag options to blanks, or click blank then click option'
AMyApp
B"MyApp"
C123
Dspark
Attempts:
3 left
💡 Hint
Common Mistakes
Forgetting to put the app name in quotes.
Using a variable name without quotes.
2fill in blank
medium

Complete the code to read a CSV file into a Spark DataFrame.

Apache Spark
df = spark.read.csv([1], header=True, inferSchema=True)
Drag options to blanks, or click blank then click option'
A"data.csv"
Bdata
Ccsv_file
Ddata.csv
Attempts:
3 left
💡 Hint
Common Mistakes
Not putting the file name in quotes.
Using a variable name without defining it.
3fill in blank
hard

Fix the error in 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"age"
Bdf.age
Cage
Ddf[age]
Attempts:
3 left
💡 Hint
Common Mistakes
Passing the column name without quotes.
Using df.age inside select which is invalid.
4fill in blank
hard

Fill both blanks to filter rows where age is greater than 30 and select the 'name' column.

Apache Spark
filtered = df.filter(df.age [1] 30).select([2])
Drag options to blanks, or click blank then click option'
A>
B"name"
C<
Dage
Attempts:
3 left
💡 Hint
Common Mistakes
Using '<' instead of '>' for filtering.
Selecting column without quotes.
5fill in blank
hard

Fill all three blanks to create a dictionary with column names as keys and their data types as values.

Apache Spark
schema_dict = [1]: [2] for [3] in df.schema.fields}
Drag options to blanks, or click blank then click option'
Afield.name
Bfield.dataType
Cfield
D{
Attempts:
3 left
💡 Hint
Common Mistakes
Not starting with '{' for dictionary comprehension.
Using wrong variable name in the loop.
Mixing up field.name and field.dataType.