Free Databricks Certified Associate Developer for Apache Spark 3.0 Exam Braindumps
Certified Associate Developer for Apache Spark Questions 41–45 (page: 10)

Updated On: 9-Feb-2026

Which of the following code blocks creates a new DataFrame with two columns season and wind_speed_ms where column season is of data type string and column wind_speed_ms is of data type double?

  1. spark.DataFrame({"season": ["winter","summer"], "wind_speed_ms": [4.5, 7.5]})
  2. spark.createDataFrame([("summer", 4.5), ("winter", 7.5)], ["season", "wind_speed_ms"]) C.
    1. from pyspark.sql import types as T
    2. spark.createDataFrame((("summer", 4.5), ("winter", 7.5)), T.StructType([T.StructField("season", T.CharType()), T.StructField("season", T.DoubleType())]))
  3. spark.newDataFrame([("summer", 4.5), ("winter", 7.5)], ["season", "wind_speed_ms"])
  4. spark.createDataFrame({"season": ["winter","summer"], "wind_speed_ms": [4.5, 7.5]})

Answer(s): B

Explanation:

spark.createDataFrame([("summer", 4.5), ("winter", 7.5)], ["season", "wind_speed_ms"])
Correct. This command uses the Spark Session's createDataFrame method to create a new DataFrame. Notice how rows, columns, and column names are passed in here: The rows are specified as a Python list. Every entry in the list is a new row. Columns are specified as Python tuples (for example ("summer", 4.5)). Every column is one entry in the tuple.
The column names are specified as the second argument to createDataFrame(). The documentation (link below) shows that "when schema is a list of column names, the type of each column will be inferred from data" (the first argument). Since values 4.5 and 7.5 are both float variables, Spark will correctly infer the double type for column wind_speed_ms. Given that all values in column "season" contain only strings, Spark will cast the column appropriately as string. Find out more about SparkSession.createDataFrame() via the link below.
spark.newDataFrame([("summer", 4.5), ("winter", 7.5)], ["season", "wind_speed_ms"]) No, the SparkSession does not have a newDataFrame method.
from pyspark.sql import types as T
spark.createDataFrame((("summer", 4.5), ("winter", 7.5)), T.StructType([T.StructField("season", T.CharType()), T.StructField("season", T.DoubleType())]))
No. pyspark.sql.types does not have a CharType type. See link below for available data types in Spark.
spark.createDataFrame({"season": ["winter","summer"], "wind_speed_ms": [4.5, 7.5]})
No, this is not correct Spark syntax. If you have considered this option to be correct, you may have some experience with Python's pandas package, in which this would be correct syntax. To create a Spark DataFrame from a Pandas DataFrame, you can simply use spark.createDataFrame(pandasDf) where pandasDf is the Pandas DataFrame.
Find out more about Spark syntax options using the examples in the documentation for SparkSession.createDataFrame linked below.

spark.DataFrame({"season": ["winter","summer"], "wind_speed_ms": [4.5, 7.5]})
No, the Spark Session (indicated by spark in the code above) does not have a DataFrame method.

More info: pyspark.sql.SparkSession.createDataFrame — PySpark 3.1.1 documentation and Data Types - Spark 3.1.2 Documentation
Static notebook | Dynamic notebook: See test 1, Question: 41 ( Databricks import instructions)



The code block shown below should return a column that indicates through boolean variables whether rows in DataFrame transactionsDf have values greater or equal to 20 and smaller or equal to 30 in column storeId and have the value 2 in column productId. Choose the answer that correctly fills the blanks in the code block to accomplish this.
transactionsDf. 1 (( 2 . 3 ) 4 ( 5 ))

  1. 1. select
    2. col("storeId")
    3. between(20, 30)
    4. and
    5. col("productId")==2
  2. 1. where
    2. col("storeId") 3. geq(20).leq(30)
    4. &
    5. col("productId")==2
  3. 1. select
    2. "storeId"
    3. between(20, 30)
    4. &&
    5. col("productId")==2
  4. 1. select
    2. col("storeId")
    3. between(20, 30)
    4. &&
    5. col("productId")=2
  5. 1. select
    2. col("storeId")
    3. between(20, 30)
    4. &
    5. col("productId")==2

Answer(s): D

Explanation:

Correct code block:
transactionsDf.select((col("storeId").between(20, 30)) & (col("productId")==2))
Although this Question: may make
you think that it asks for a filter or where statement, it does not. It asks explicity to return a column with booleans – this should point you to the select statement.
Another trick here is the rarely used between() method. It exists and resolves to ((storeId >= 20) AND (storeId <= 30)) in SQL. geq() and leq() do not exist.
Another riddle here is how to chain the two conditions. The only valid answer here is &. Operators like && or and are not valid. Other boolean operators that would be valid in Spark are | and.
Static notebook | Dynamic notebook: See test 1, Question: 42 (Databricks import instructions)



Which of the following code blocks displays the 10 rows with the smallest values of column value in DataFrame transactionsDf in a nicely formatted way?

  1. transactionsDf.sort(asc(value)).show(10)
  2. transactionsDf.sort(col("value")).show(10)
  3. transactionsDf.sort(col("value").desc()).head()
  4. transactionsDf.sort(col("value").asc()).print(10)
  5. transactionsDf.orderBy("value").asc().show(10)

Answer(s): B

Explanation:

show() is the correct method to look for here, since the Question: specifically asks
for displaying the rows in a nicely formatted way. Here is the output of show (only a few rows shown):

With regards to the sorting, specifically in ascending order since the smallest values should be shown first, the following expressions are valid:
- transactionsDf.sort(col("value")) ("ascending" is the default sort direction in the sort method)
- transactionsDf.sort(asc(col("value")))
- transactionsDf.sort(asc("value"))
- transactionsDf.sort(transactionsDf.value.asc())
- transactionsDf.sort(transactionsDf.value)
Also, orderBy is just an alias of sort, so all of these expressions work equally well using orderBy. Static notebook | Dynamic notebook: See test 1, Question: 43 (Databricks import instructions)



Which of the following code blocks uses a schema fileSchema to read a parquet file at location filePath into a DataFrame?

  1. spark.read.schema(fileSchema).format("parquet").load(filePath)
  2. spark.read.schema("fileSchema").format("parquet").load(filePath)
  3. spark.read().schema(fileSchema).parquet(filePath)
  4. spark.read().schema(fileSchema).format(parquet).load(filePath)
  5. spark.read.schema(fileSchema).open(filePath)

Answer(s): A

Explanation:

Pay attention here to which variables are quoted. fileSchema is a variable and thus should not be in quotes. parquet is not a variable and therefore should be in quotes.
SparkSession.read (here referenced as spark.read) returns a DataFrameReader which all subsequent calls reference - the DataFrameReader is not callable, so you should not use parentheses here.
Finally, there is no open method in PySpark. The method name is load. Static notebook | Dynamic notebook: See test 1, Question: 44 ( Databricks import instructions)



Which of the following code blocks returns only rows from DataFrame transactionsDf in which values in column productId are unique?

  1. transactionsDf.distinct("productId")
  2. transactionsDf.dropDuplicates(subset=["productId"])
  3. transactionsDf.drop_duplicates(subset="productId")
  4. transactionsDf.unique("productId")
  5. transactionsDf.dropDuplicates(subset="productId")

Answer(s): B

Explanation:

Although the Question: suggests using
a method called unique() here, that method does not actually exist in PySpark. In PySpark, it is called distinct(). But then, this method is not the right one to use here, since with distinct() we could filter out unique values in a specific column.
However, we want to return the entire rows here. So the trick is to use dropDuplicates with the subset keyword parameter. In the documentation for dropDuplicates, the examples show that subset should be used with a list. And this is exactly the key to solving this question: The productId column needs to be fed into the subset argument in a list, even though it is just a single column.
More info: pyspark.sql.DataFrame.dropDuplicates — PySpark 3.1.1 documentation
Static notebook | Dynamic notebook: See test 1, Question: 45 (Databricks import instructions)



Viewing page 10 of 37
Viewing questions 46 - 50 out of 342 questions


Post your Comments and Discuss Databricks Databricks Certified Associate Developer for Apache Spark 3.0 exam prep with other Community members:

AI Tutor AI Tutor 👋 I’m here to help!