Fill nulls
Fill nulls — fillNulls
Replace missing values using a strategy.
Use cases
- Backfill a constant like
"Unknown"for a missing category. - Impute a numeric column with its mean/median so rows aren't lost.
- Carry the last known value forward (
ffill) in a time series.
What it does
Replaces nulls in the target columns without removing rows — unlike Drop nulls, every row survives.
Before
| order_id | region | amount |
|---|---|---|
| 1001 | North | 120.5 |
| 1002 | null | 89 |
| 1003 | South | null |
| 1004 | null | 42.25 |
4 rows · 3 cols
Fill nulls (strategy=constant, value=Unknown, columns=[region])
After
| order_id | region | amount |
|---|---|---|
| 1001 | North | 120.5 |
| 1002 | Unknown | 89 |
| 1003 | South | null |
| 1004 | Unknown | 42.25 |
4 rows · 3 cols
Configuration
| Config key | Type | Required | Description |
|---|---|---|---|
strategy | string | No | constant (default), mean, median, mode, min, max, zero, ffill, bfill |
value | any | Conditional | Required when strategy is constant |
columns | string[] | No | Limit to these columns (otherwise all) |
The mean, median, min, and max strategies are computed per column from
the non-null values; mode uses the most frequent value; ffill/bfill
propagate the previous/next value.
Generated Python code
# strategy: "constant", value: "Unknown", columns: ["region"]
df_2 = df_1.fillna({'region': 'Unknown'})
Tips & common mistakes
- A
valueis only needed forconstant. Computed strategies (mean, median, …) ignore it. mean/medianneed numeric columns. Restrictcolumnsso the strategy only touches columns it applies to.