Pandas on spark
Skill Galius5136/databricks-spark-3.5-cert-prep/skills/pandas-on-spark
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).From its SKILL.md
npx -y skills add Galius5136/databricks-spark-3.5-cert-prep --skill pandas-on-sparkAssembled from the repository path, not quoted from the project. Check it against their README if it does not work.
2 things to look at
- 12 stars12 stars. Stars are a popularity signal and not a quality one, but at this level it is likely that nobody has read this closely except its author, and you would be relying on your own review.
- fetches URLsInstructs the agent to fetch 5 URLs, including https://spark.apache.org/docs/3.5.7/api/python/user_guide/pandas_on_spark/index.html and 4 more.
SKILL.md
8.6 KB, ~2.2k tokens by cl100k_base, as published. Nobody here has run it
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 # attribute
ps.get_option("display.max_rows") # function
ps.set_option("display.max_rows", 50)
ps.reset_option("display.max_rows")
with ps.option_context("compute.max_rows", 5000):
... # temporary
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 planpsdf.spark.local_checkpoint()to truncate long lineagesGroupBy.rank()instead ofDataFrame.rank()(avoids SinglePartition).apply(fn)with return type hint instead of Pythonforloops.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=Trueto "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.pandasAPI 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()→ ch01compute.*options → ch01- Conversions (pandas / pandas-on-Spark / PySpark) → ch01
- Default index type → ch01
distributedvsdistributed-sequencevssequence→ ch01from_pandas→ ch01get_option/set_option/option_context→ ch01- Koalas merger / Project Zen → ch01
- Lazy execution → ch01
ops_on_diff_frames→ ch01.pandas_api()→ ch01pyspark.pandas→ ch01.spark.checkpoint()/.spark.local_checkpoint()→ ch01.spark.explain()→ ch01.to_pandas()/.to_spark()→ ch01- Three-DataFrame model → ch01
Supporting Files
- glossary.md — terms with chapter pointers
- patterns.md — concrete techniques + when/how/trade-offs
- cheatsheet.md — single-page exam reference + post-3.5 traps
Sources used
Apache Spark 3.5.7 user guide (primary):
- https://spark.apache.org/docs/3.5.7/api/python/user_guide/pandas_on_spark/index.html
- https://spark.apache.org/docs/3.5.7/api/python/user_guide/pandas_on_spark/pandas_pyspark.html
- https://spark.apache.org/docs/3.5.7/api/python/user_guide/pandas_on_spark/options.html
- https://spark.apache.org/docs/3.5.7/api/python/user_guide/pandas_on_spark/best_practices.html
Databricks blog (historical context):
To regenerate local snapshots: fetch each URL above and extract the relevant sections (the chapter file
ch01-pandas-on-spark.mdsynthesizes 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.
What ships with it: 4 files
26.2 KB alongside SKILL.md
chapters/
- ch01-pandas-on-spark.md10.5 KB
- cheatsheet.md4.6 KB
- glossary.md4.6 KB
- patterns.md6.4 KB