0
0
Apache Sparkdata~10 mins

Databricks platform overview 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 create a Spark session in Databricks.

Apache Spark
from pyspark.sql import SparkSession
spark = SparkSession.builder.appName([1]).getOrCreate()
Drag options to blanks, or click blank then click option'
Aspark
BMyApp
C"MyApp"
DappName
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 DataFrame in Databricks.

Apache Spark
df = spark.read.format([1]).option("header", "true").load("/mnt/data/sample.csv")
Drag options to blanks, or click blank then click option'
A"json"
B"csv"
C"parquet"
D"text"
Attempts:
3 left
💡 Hint
Common Mistakes
Using the wrong format like "json" or "parquet".
Not putting the format name in quotes.
3fill in blank
hard

Fix the error in the code to display the first 5 rows of the DataFrame.

Apache Spark
df.[1](5).show()
Drag options to blanks, or click blank then click option'
Alimit
Bhead
Cshow
Dtake
Attempts:
3 left
💡 Hint
Common Mistakes
Using head(5) which returns a list, not a DataFrame.
Using 'show', which returns None and causes an AttributeError when chaining .show().
4fill in blank
hard

Fill both blanks to create a DataFrame with only rows where the age is greater than 30.

Apache Spark
filtered_df = df.filter(df.[1] [2] 30)
Drag options to blanks, or click blank then click option'
Aage
B>
C<
Dsalary
Attempts:
3 left
💡 Hint
Common Mistakes
Using the wrong column name like 'salary'.
Using the less than operator '<' instead of '>'.
5fill in blank
hard

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

Apache Spark
lengths = { [1]: [2] for [3] in words if len([3]) > 3 }
Drag options to blanks, or click blank then click option'
Aword
Blen(word)
Ditem
Attempts:
3 left
💡 Hint
Common Mistakes
Using different variable names inconsistently.
Mapping key to the wrong value.