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

