last(ignorenulls)
Forward-fill missing values with last over a window, and the frame that makes it work.
Step 1 · PySpark functions · Gold · Gold window patterns, lesson 2 of 3
On this page
Read first: rangeBetween · lag / lead (skip if you know them)
In plain words first
A thermometer that only writes down the temperature when it changes leaves blank lines in between. To read the temperature at any line, you look up to the last line that has a number.
That is a forward fill: last(col, ignorenulls=True) over all rows up to the current one.
Unlock the full lesson
You have read the free part. The rest of this advanced lesson:
- What it does
- Step by step
- Run the example
- Why the explicit frame
- Back-filling
- When not to forward-fill
- Common mistakes
- Key takeaways
- Interview prep with 3 follow-up questions
- Check yourself: 3 questions
Unlock it with the Complete pass (every advanced problem and lesson) or on its own.
Practise this
Problems that use last(ignorenulls), graded on hidden tests
Keep going
Up next · Gold window patterns · lesson 3 of 3 · 7 min readGaps and islands
Streaks, sessions and status runs: one window pattern behind many interview questions.
Related lessons
rangeBetweenPySpark functions · 4 min read
lag / leadPySpark functions · 4 min read
coalesce
Previous: rangeBetween
Primary sources: functions.last · Window functions (SQL)