Typorithm · easy

select & filter

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

Step 1 of 8 · intro card

Learn select & filter

0%

DataFrames

select projects a subset of columns; filter keeps only the rows matching a condition. Build conditions with col("age") expressions, then show() to run the chain.

select narrows a DataFrame to the columns you name, producing a new DataFrame — the original is never modified.

filter keeps only rows where a boolean expression is true; col("age") references a column so col("age") > 18 evaluates per row.

select and filter are lazy transformations: nothing runs until an action like show() triggers the whole chain at once.

01

select projects a subset of columns.

02

filter keeps rows matching a condition.

03

col("name") references a column in expressions.

df.select("name", "age").filter(col("age") > 18).show();

Read the implementation

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

1. Project columns

select keeps only the named columns, returning a new DataFrame with just name and age.

df.select("name", "age")

2. Filter rows

filter keeps only the rows where the boolean column expression is true.

.filter(col("age") > 18)

3. Column expression

col("age") references the age column so it can be compared inside an expression.

col("age")

4. Trigger the result

show() is an action that runs the chained transformations and prints the result.

.show();

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.

select & filter: Lesson & Practice · Typorithm | ApplyDjinn