# Fill with the mean, median or mode

Shape / columns

A variant of [Fill in missing values](https://meridian.online/operations/fill-in-missing-values).

Replace missing values with a statistic of the column, such as its mean, median or mode.

Page: <https://meridian.online/operations/fill-in-missing-values/fill-with-a-column-statistic>

## Status

Runs as a SQL step.

arcform carries it as a `sql:` step today.

## The DuckDB step

fill missing values with the mean, median or mode of the column

It reads the `orders` table the proofs share. Create it first:

```sql
CREATE TABLE orders AS SELECT * FROM (VALUES
  (1,  'Alice Ng',      'north', DATE '2026-01-03', 120.00, 'widget', 'a|b',   '{"channel":"web","items":[1,2]}'),
  (2,  'alice ng',      'north', DATE '2026-01-05',  80.50, 'gadget', 'b',     '{"channel":"shop","items":[3]}'),
  (3,  'Bob  Okafor',   'south', DATE '2026-01-05', 300.00, 'widget', 'a|c',   '{"channel":"web","items":[4,5,6]}'),
  (4,  'Carla Díaz',    'east',  DATE '2026-01-09',  NULL,  'gizmo',  NULL,    '{"channel":"web","items":[]}'),
  (5,  'Bob Okafor',    'south', DATE '2026-01-12',  45.25, 'gadget', 'c',     '{"channel":"phone","items":[7]}'),
  (6,  'Dev Patel',     'west',  DATE '2026-01-12', 510.00, 'widget', 'a',     '{"channel":"web","items":[8,9]}'),
  (7,  'Carla Diaz',    'east',  DATE '2026-01-20',  99.99, 'gizmo',  'b|c',   '{"channel":"shop","items":[10]}'),
  (8,  'Dev Patel',     'west',  DATE '2026-02-02', 510.00, 'widget', 'a',     '{"channel":"web","items":[8,9]}'),
  (9,  'Eve Larsen',    NULL,    DATE '2026-02-03',  15.00, 'gadget', NULL,    '{"channel":"web","items":[11]}'),
  (10, 'Alice Ng',      'north', DATE '2026-02-10', 220.00, 'gizmo',  'a|b|c', '{"channel":"phone","items":[12,13]}')
) t(order_id, customer, region, order_date, amount, product, tags, meta);
```

Then run the statement:

```sql
CREATE TEMP TABLE result AS
SELECT order_id, amount,
       round(coalesce(amount, avg(amount) OVER ()), 2) AS filled_mean,
       coalesce(amount, median(amount) OVER ())::DOUBLE AS filled_median,
       coalesce(amount, mode(amount) OVER ())::DOUBLE AS filled_mode
FROM orders;
SELECT * FROM result ORDER BY order_id;
SELECT CASE WHEN ((SELECT [filled_mean, filled_median, filled_mode] FROM result WHERE order_id = 4) = [211.19, 120.0, 510.0] AND (SELECT [filled_mean, filled_median, filled_mode] FROM result WHERE order_id = 1) = [120.0, 120.0, 120.0] AND (SELECT count(*) FROM result WHERE filled_mean IS NULL OR filled_median IS NULL OR filled_mode IS NULL) = 0) THEN 'as expected' ELSE error('the missing amount was not filled with the mean 211.19, the median 120 and the mode 510, or a present amount changed') END AS verdict;
```

It needs nothing installed beyond DuckDB itself.

## What other tools call it

Meridian's classification; an independent blind rating agreed on 95.7% of 324 rows (variant, version 3).

- Alteryx Designer: [`Imputation`](https://help.alteryx.com/current/en/designer/tools/preparation/imputation-tool.html) (read 2026-09-27)
- AWS Glue: [`FillWithMode`](https://docs.aws.amazon.com/glue/latest/dg/aws-glue-api-pyspark-transforms-FillWithMode.html) (read 2026-09-27)
- KNIME Analytics Platform: [`Missing Value`](https://api.hub.knime.com/nodes/*uVmaGQkzUOFCTqUe?details=full) (read 2026-09-27)
- KNIME Analytics Platform: [`Missing Value (Apply)`](https://api.hub.knime.com/nodes/*MtI-i19EnG7ZKJC7?details=full) (read 2026-09-27)
- mlpack: [`Imputation`](https://www.mlpack.org/doc/user/preprocessing.html) (read 2026-09-27)
- Polars: [`DataFrame.fill_null`](https://docs.pola.rs/api/python/stable/reference/dataframe/modify_select.html) (read 2026-09-27)
- Polars: [`Expr.fill_null`](https://docs.pola.rs/api/python/stable/reference/expressions/modify_select.html) (read 2026-09-27)
- RapidMiner Studio: [`Replace All Missings`](https://docs.rapidminer.com/latest/studio/operators/cleansing/missing/universal_missing_value_handling.html) (read 2026-09-27)
- RapidMiner Studio: [`Replace Missing Values`](https://docs.rapidminer.com/latest/studio/operators/cleansing/missing/replace_missing_values.html) (read 2026-09-27)
- RapidMiner Studio: [`Replace Missing Values (In Database)`](https://docs.rapidminer.com/latest/studio/operators/extensions/In-Database%20Processing/indb_cleansing/indb_replace_missing.html) (read 2026-09-27)
