Databricks Certified Machine Learning Associate · Free Practice Question Medium
Question 5
What is the potential reason for the reduced performance speed when using the pandas API compared to native Spark DataFrames, especially for large datasets?
Choose only ONE best answer.
-
A
The employment of an internalFrame to maintain metadata
-
B
The requirement for an increased amount of code
-
C
The dependence on CSV files
-
D
The immediate evaluation of all processing operations
-
E
The absence of data distribution
Reveal correct answer
Correct answer: A
Explanation
Correct Answer:
The employment of an internalFrame to maintain metadata
Explanation:
The pandas API on Spark (Koalas) introduces an internalFrame layer to bridge pandas-like operations with Spark's distributed execution. While this enables familiar syntax, it adds overhead due to:
Metadata Management:
The
internalFrametracks pandas-like indices, column names, and data types, requiring extra bookkeeping.
Conversion Costs:
Pandas operations are translated to Spark plans via this layer, which can slow down execution compared to native Spark DataFrames.
Example Impact:
- import pyspark.pandas as ps
- # pandas API on Spark (uses internalFrame)
- kdf = ps.DataFrame(...)
- result = kdf.groupby("col1").sum() # Slower due to metadata handling
- # Native Spark (direct execution)
- sdf = spark.createDataFrame(...)
- result = sdf.groupBy("col1").sum() # Faster
Why Other Options Are Incorrect:
"Increased code amount":
Irrelevant; performance is about execution, not code volume.
"Dependence on CSV files":
Unrelated; data source format doesn’t affect API performance.
"Immediate evaluation":
Both APIs use lazy evaluation.
"Absence of data distribution":
False; pandas API on Spark does distribute data (unlike vanilla pandas).
Key Takeaway:
For large datasets, prefer native Spark DataFrames when:
✅ Performance is critical (avoid internalFrame overhead).
✅ Advanced Spark optimizations (e.g., predicate pushdown) are needed.
Use pandas API on Spark for:
✅ Pandas familiarity on small-to-medium distributed data.
Discussion
Think the marked answer is wrong, or have a better explanation? Share it below — comments appear after review.
