Skip to content
Cheat sheets/PySpark handbook

PySpark handbook

Take the same data workflow from a laptop to a cluster — without rethinking the problem.

From SparkSession to DataFrames and ML

12 MIN25 ENTRIES5 GROUPSUPDATED 2026-11-18

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

01

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.

02

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.

03

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.

04

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.

05

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.

§ CREDITSource and curation

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.