Question 1
Which pandas UDF type processes an iterator of batches, useful when expensive initialization such as loading a model should happen once per partition?
- Series to scalar with a broadcast model
- Grouped map with applyInPandas only
- Row-at-a-time UDF
- Iterator of Series to Iterator of Series — Correct
Correct answer
Iterator of Series to Iterator of Series
Explanation
The iterator form lets the function run setup code once and then process multiple batches.
Question 2
Which method applies a Python function that takes and returns a pandas DataFrame to each group of a Spark DataFrame?
- df.groupBy('k').applyInPandas(func, schema) — Correct
- df.groupBy('k').mapInPandas(func, schema)
- df.applyPandas('k', func)
- df.groupBy('k').agg(func)
Correct answer
df.groupBy('k').applyInPandas(func, schema)
Explanation
applyInPandas runs a function on each group as a pandas DataFrame and returns a DataFrame matching the schema.
Question 3
Which import is used for the pandas API on Spark?
- import pandas.spark as ps
- from pyspark.sql import pandas as ps
- import pyspark.pandas as ps — Correct
- import koalas.spark as ps
Correct answer
import pyspark.pandas as ps
Explanation
The pandas API on Spark lives in pyspark.pandas (it evolved from the Koalas project).
Question 4
Which code reads a CSV file into a pandas-on-Spark DataFrame?
- ps.read_csv('/data/sales.csv') — Correct
- ps.load('/data/sales.csv', 'csv')
- pd.read_csv('/data/sales.csv').to_spark()
- spark.read.pandas('/data/sales.csv')
Correct answer
ps.read_csv('/data/sales.csv')
Explanation
pyspark.pandas provides read_csv, read_parquet and similar functions that load data in a distributed way.
Question 5
What is an advantage of the pandas API on Spark?
- It guarantees identical performance to pandas on small data
- It supports every pandas function with identical behavior
- pandas syntax on data too big for one machine — Correct
- It removes the need for a Spark cluster
Correct answer
pandas syntax on data too big for one machine
Explanation
pyspark.pandas provides a pandas-like API backed by distributed Spark execution. Some behaviors and functions differ from pandas.
Question 6
Which statement about the default index in pandas API on Spark is correct?
- Indexes are not supported
- Creating it can cost extra computation; its type is configurable — Correct
- Every pandas-on-Spark DataFrame is indexed by a Spark partition ID that is free to compute
- The index is always stored in driver memory
Correct answer
Creating it can cost extra computation; its type is configurable
Explanation
pandas-on-Spark attaches a default index (sequence, distributed-sequence or distributed), each with different cost trade-offs.
Question 7
Which statement about the pandas API on Spark compared with pandas is correct?
- It requires converting data to RDDs first
- It loads all data into the driver like pandas
- Execution is distributed and some pandas behaviors differ — Correct
- It supports only reading data, not transformations
Correct answer
Execution is distributed and some pandas behaviors differ
Explanation
pandas-on-Spark executes with Spark; ordering and some APIs differ from single-node pandas.
Question 8
Which Spark component lets pandas users run familiar pandas-style code on distributed data?
- Spark Core RDD API
- Structured Streaming
- GraphX
- Pandas API on Spark — Correct
Correct answer
Pandas API on Spark
Explanation
The pandas API on Spark (pyspark.pandas) implements much of the pandas API on top of Spark DataFrames.
Question 9
Which code converts a Spark DataFrame sdf into a pandas-on-Spark DataFrame without collecting it to the driver?
- sdf.pandas_api() — Correct
- sdf.toPandas()
- pd.DataFrame(sdf)
- sdf.collect().to_pandas()
Correct answer
sdf.pandas_api()
Explanation
pandas_api() returns a pyspark.pandas DataFrame that stays distributed. toPandas collects data to the driver.
Question 10
Which pandas UDF type is used for grouped aggregation that returns one value per group?
- Iterator of Series to Iterator of Series
- DataFrame to Row
- Series to scalar — Correct
- Series to Series
Correct answer
Series to scalar
Explanation
A Series-to-scalar pandas UDF can be used with groupBy().agg() to return one value per group.