| name | pandas-on-spark |
| description | Knowledge base for Pandas API on Spark (pyspark.pandas) โ Apache Spark 3.5. Use when preparing for Sec 7 objective 'Explain advantages of using Pandas API on Spark', migrating pandas code to scale on Spark, or configuring pyspark.pandas options (default index type, ops_on_diff_frames, checkpointing). Sources: spark.apache.org 3.5.7 docs + Databricks blog (Koalas merger). NOT covered here: Pandas UDF (separate skill), Spark Connect (see skill spark-connect). |
| allowed-tools | ["Read","Grep"] |
| argument-hint | ["topic or chapter number"] |
Pandas API on Spark โ Exam-Prep Knowledge Base
Source Spark version: 3.5.7 + 2021 Databricks Koalas-merger context | Chapters: 1 (single deep-dive) | Generated: 2026-05-24
Scope rule: All content is in scope for Sec 7 of the Databricks Certified Associate Developer for Apache Spark exam, anchored to Spark 3.5. Anything Spark 4.x is flagged โ ๏ธ.
Out of scope for this skill (cross-links only, no expansion):
- Pandas UDF (
@pandas_udf) โ same exam section but a different API; covered by a separate skill.
- Spark Connect โ see skill
spark-connect.
How to Use This Skill
- Without arguments โ loads the Core Frameworks below.
- By topic โ ask about
default index type, to_pandas, ops_on_diff_frames, checkpoint, Koalas, etc.
- By chapter โ only
ch01; the topic is single-chapter sized.
Core Frameworks & Mental Models
Pandas API on Spark in one paragraph
pyspark.pandas is a pandas-compatible DataFrame API that executes distributed on Spark. It started as the standalone Koalas project (Databricks) and was merged into PySpark with Spark 3.2 (Sept-Oct 2021, via the SPIP under Project Zen). Goal: let pandas users scale from single-machine to multi-TB cluster workloads with a single import change (import pandas as pd โ import pyspark.pandas as pd), while keeping the entire downstream code identical.
Why use it (advantages โ exam objective 1)
- Familiar pandas syntax at Spark scale โ minimal code change to scale.
- No extra install since Spark 3.2 โ ships with PySpark.
- Single-machine speedup via Catalyst optimizer + whole-stage codegen (Databricks 2021 benchmark: ~4ร faster join on 130 GB CSV vs native pandas; survives chain operations where pandas OOMs).
- Linear scalability โ same job runs on 60 GB single-machine or 15 TB on 256-node cluster (Databricks benchmark: ~10s std-dev compute in both cases).
- Unified analytics โ same DataFrames feed
ps.sql(...), Spark Structured Streaming, and MLlib.
- Lazy execution โ Catalyst plans and optimizes; jobs trigger only when needed.
- All Spark features work โ web UI, history server, AQE, dynamic allocation, deployment modes.
The three DataFrames
| API | Where | Use case |
|---|
| pandas | single machine | data fits in RAM |
pyspark.pandas (Pandas API on Spark) | distributed on Spark | large data, pandas syntax |
| PySpark DataFrame | distributed on Spark | low-level Spark control, SQL |
Conversions (cheat)
| From โ To | Method |
|---|
| pandas-on-Spark โ pandas | psdf.to_pandas() โ ๏ธ collects to driver |
| pandas โ pandas-on-Spark | ps.from_pandas(pdf) |
| pandas-on-Spark โ PySpark | psdf.to_spark(index_col='โฆ') |
| PySpark โ pandas-on-Spark | sdf.pandas_api(index_col='โฆ') |
Always pass index_col on the Spark roundtrip to skip default-index regeneration.
Options system (4 ways to interact)
import pyspark.pandas as ps
ps.options.display.max_rows
ps.get_option("display.max_rows")
ps.set_option("display.max_rows", 50)
ps.reset_option("display.max_rows")
with ps.option_context("compute.max_rows", 5000):
...
Default index types โ exam-worthy
| Value | Distribution | Sequential? | Performance | Use case |
|---|
'sequence' | single partition | yes | poor on large data | small datasets only |
'distributed-sequence' (default) | distributed | yes | medium | production default |
'distributed' | distributed | no (indeterministic) | best | when index values don't matter |
Critical rule: never combine 'distributed' index with compute.ops_on_diff_frames=True โ indeterministic alignment โ wrong results.
Top options to know (Spark 3.5 defaults)
| Option | Default | Behavior |
|---|
compute.default_index_type | 'distributed-sequence' | Index strategy |
compute.ops_on_diff_frames | False | Block expensive cross-DF implicit join |
compute.max_rows | 1000 | Shortcut threshold (collectโpandas) |
compute.shortcut_limit | 1000 | Rows for schema inference |
compute.eager_check | True | Upfront validation |
compute.isin_limit | 80 | isin(list) โฅ this โ broadcast join |
display.max_rows | 1000 | Repr cap |
plotting.backend | 'plotly' | or 'matplotlib' |
Best-practice signals
- Configure Spark BEFORE
import pyspark.pandas
- Enable Arrow:
.config("spark.sql.execution.arrow.pyspark.enabled", "true")
psdf.spark.explain() to inspect the plan
psdf.spark.local_checkpoint() to truncate long lineages
GroupBy.rank() instead of DataFrame.rank() (avoids SinglePartition)
.apply(fn) with return type hint instead of Python for loops
.max() / .min() / .sum() methods, NOT Python built-ins (max(s) fails)
Anti-patterns
max(ps_series) / for v in ps_series: โ no __iter__ on purpose
.to_pandas() on multi-GB data โ driver OOM
'distributed' index + ops_on_diff_frames=True โ broken alignment
- Duplicate / case-conflict column names โ Spark SQL rejects
- Reserved column names
__foo__ โ internal use
DataFrame.rank() on large data โ collapses to one partition
- Flipping
compute.ops_on_diff_frames=True to "just make it work" โ implicit expensive join
Exam Sec 7 โ coverage mapping
| Sec 7 objective | This skill | Other skill |
|---|
| "Explain advantages of using Pandas API on Spark" | โ
fully covered | โ |
| "Create and invoke Pandas UDF" | โ different topic | (separate Pandas UDF skill โ TBD) |
โ Post-3.5 โ DO NOT memorize for the 3.5 exam
- Any
pyspark.pandas API additions in Spark 4.0+ are out of scope.
- The 3.5 defaults shown above are the canonical exam target.
Chapter Index
| # | Title | Focus |
|---|
| ch01 | Pandas API on Spark | Single deep-dive: advantages, conversions, options, best practices, anti-patterns |
Topic Index
.apply() โ ch01
compute.* options โ ch01
- Conversions (pandas / pandas-on-Spark / PySpark) โ ch01
- Default index type โ ch01
distributed vs distributed-sequence vs sequence โ ch01
from_pandas โ ch01
get_option / set_option / option_context โ ch01
- Koalas merger / Project Zen โ ch01
- Lazy execution โ ch01
ops_on_diff_frames โ ch01
.pandas_api() โ ch01
pyspark.pandas โ ch01
.spark.checkpoint() / .spark.local_checkpoint() โ ch01
.spark.explain() โ ch01
.to_pandas() / .to_spark() โ ch01
- Three-DataFrame model โ ch01
Supporting Files
Sources used
Apache Spark 3.5.7 user guide (primary):
Databricks blog (historical context):
To regenerate local snapshots: fetch each URL above and extract the relevant sections (the chapter file ch01-pandas-on-spark.md synthesizes them).
Scope & Limits
This skill is calibrated for Sec 7 of the Databricks Certified Associate Developer for Apache Spark exam, scoped strictly to pyspark.pandas at Spark 3.5. For Pandas UDF (the other Sec 7 objective), use the dedicated Pandas UDF skill. For Spark Connect, see skill spark-connect.