PySpark handbook
Take the same data workflow from a laptop to a cluster — without rethinking the problem.
From SparkSession to DataFrames and ML
What you'll take away
Build DataFrames and query them with Spark SQL
Keep jobs fast with lazy transforms and fewer shuffles
Carry one dataset all the way into ML pipelines
25 entries · click a command to copy
Setup and SparkSession
Install PySpark in your Python environment.
Import the entry point for DataFrame APIs.
Create or reuse a local SparkSession.
Check the running Spark version.
Create and inspect DataFrames
Build a DataFrame from Python rows and a declared schema.
Read a CSV with column names and type inference.
Display rows in a formatted table.
Inspect column names and types.
Count rows across the cluster.
Transformations (lazy)
Choose columns to keep.
Keep rows matching a condition.
Add or replace a derived column.
Aggregate by group.
Remove duplicate rows on selected keys.
Join two DataFrames.
Actions and output
Return all rows to the driver — only for small results.
Tip: Use df.take(n) or df.show() for exploration.
Persist a DataFrame in columnar Parquet format.
Write CSV, replacing an existing output directory.
Expose a DataFrame for Spark SQL queries.
Run SQL against registered views.
Machine learning pipelines
Combine feature columns into a vector.
Declare the feature vector for a model.
Import a distributed classifier.
Train a model on a Spark DataFrame.
Generate predictions for evaluation.
This sheet was curated from reference material in the Skyware AI technical library (Complete PySpark guide (local Tech-docs material)). Command syntax is factual; explanations, grouping and examples were written by our engineering team. Always verify syntax against your tool or database version.
More cheat sheets
Git commands
A practical Git reference grouped by task: setup, inspecting changes, commits, branches, remotes and undoing mistakes.
OpenSQL data cleaning
A task-oriented SQL reference for string cleanup, NULL handling, type conversion, dates, aggregation and deduplication.
OpenPandas essentials
The core Pandas operations you reach for daily, organised by task with short, copyable examples.
Open