Start here
A DataFrame is a table that Spark can spread over many machines. You met it in the chapter "What Apache Spark Is & Why It Exists". In this chapter you look closer at how it works.
From "Transformations, Actions & Lazy Evaluation" you know transformations, actions, and explain(). Here you learn the parts you use in every Spark job.
A DataFrame also has partitions, the pieces you saw in the architecture chapter. You think in rows and columns. Spark runs the work on partitions.
- The schema: the names and types of the columns.
- Columns and expressions: select, withColumn, when, and cast.
- The same query in the DataFrame API and in SQL.
- NULL values: what sum, avg, and count do with them.
- Datasets, Row objects, and toPandas().
The data is the shop. The table orders has six rows, orders 101 to 106. Here they are.
| order_id | customer_id | status | amount | order_date |
|---|---|---|---|---|
| 101 | 1 | paid | 40.00 | 2026-01-03 |
| 102 | 1 | paid | 25.00 | 2026-01-10 |
| 103 | 2 | refunded | 60.00 | 2026-01-11 |
| 104 | 3 | paid | 15.50 | 2026-01-15 |
| 105 | 3 | pending | NULL | 2026-01-20 |
| 106 | 4 | paid | 80.00 | 2026-01-21 |
orders.show()| order_id | customer_id | status | amount | order_date |
|---|---|---|---|---|
| 101 | 1 | paid | 40.00 | 2026-01-03 |
| 102 | 1 | paid | 25.00 | 2026-01-10 |
| 103 | 2 | refunded | 60.00 | 2026-01-11 |
| 104 | 3 | paid | 15.50 | 2026-01-15 |
| 105 | 3 | pending | NULL | 2026-01-20 |
| 106 | 4 | paid | 80.00 | 2026-01-21 |
