Typorithm · easy

Read & Show

df-read-showsparkreadshowschema
Saved on this device
Full lesson · 8 learning steps Open any exercise for focused practice
1

Step 1 of 8 · intro card

Learn Read & Show

0%

DataFrames

spark.read loads data into a DataFrame; chain .option("header", true) so the first row becomes column names. show() previews rows and printSchema() reveals each column's inferred type.

A DataFrame is a distributed table of rows and named, typed columns — Spark's core abstraction for structured data.

spark.read returns a reader; chaining .option("header", true).csv("data.csv") loads the file and treats the first row as headers.

Once loaded, show() prints the first rows as a table and printSchema() lists every column with its inferred type, so you can confirm the data was parsed correctly.

01

spark.read loads data into a DataFrame.

02

show() previews the first rows.

03

printSchema() lists columns and their types.

const df = spark.read.option("header", true).csv("data.csv");
df.show();
df.printSchema();

Read the implementation

Connect each part of the code to the concept before you type.

1. Read into a DataFrame

spark.read builds a DataFrameReader; .csv loads the file into a distributed DataFrame.

spark.read.option("header", true).csv("data.csv")

2. Reader option

option("header", true) treats the first row as column names instead of data.

.option("header", true)

3. Show rows

show() prints the first 20 rows of the DataFrame in a table for a quick look.

df.show();

4. Inspect the schema

printSchema() prints each column with its inferred type, so you can verify the shape.

df.printSchema();

A complete learning loop

01

Understand

Read the concept map and follow the code breakdown.

02

Reconstruct

Type the implementation, repair mistakes and work through every recall exercise.

03

Verify

Use the final check without hints; revisit weak concepts in short practice sessions.

Read & Show: Lesson & Practice · Typorithm | ApplyDjinn