Filling Missing Values
Replace missing values with meaningful data using fillna() and other methods.
Fill with a Constant
Replace all NaN with a single value:
Loading Pandas Playground...
Fill with Column-Specific Values
Use a dictionary for different fill values:
Loading Pandas Playground...
Fill with Statistics
Use mean, median, or mode:
Loading Pandas Playground...
Forward and Backward Fill
Propagate previous or next values:
Loading Pandas Playground...
Interpolation
Fill based on surrounding values:
Loading Pandas Playground...
Limiting Fill
Limit how many consecutive NaN to fill:
Loading Pandas Playground...
Exercise: Fill with Mean
Loading Exercise...
Exercise: Forward Fill
Loading Exercise...
Key Points
fillna(value)replaces NaN with constant- Use dict for column-specific fill values
- Fill with statistics:
fillna(df['col'].mean()) ffill()propagates last valid value forwardbfill()propagates next valid value backwardinterpolate()fills based on surrounding valueslimit=restricts consecutive fills
Up next · Lesson 26 of 42
Dropping Missing Values
1 min read
25 of 42 lessons done

Ask Byte about this lesson
A private chat about this lesson. Byte has read the whole lesson, answers in seconds, and shows the section each answer comes from. Ask follow-ups in any language.
Questions & Answers
Public questions about this lesson. The AI Tutor answers right away in your language, the FreeAcademy team checks answers, and every learner can read them.

