# Missing Value Imputer

Fill missing cells in a CSV with mean, median, most-frequent, a constant, or KNN imputation. Pick columns and missing markers. Runs in your browser, free.

## Run it

- **CLI:** `gizza tool missing-value-imputer "name,age,city
Alice,30,NYC
Bob,,LA
Carol,40,"`
- **Web:** https://gizza.ai/tools/missing-value-imputer/
- **Agents:** machine-readable descriptor (parameters JSON Schema) at https://gizza.ai/tools/missing-value-imputer/tool.json

## Inputs

- `input` — CSV _(field)_
- `strategy` — Imputation strategy _(field)_
- `header` — First row is a header (kept, used for column names) _(field)_
- `delimiter` — Delimiter _(field)_
- `columns` — Columns to impute (blank = all) _(field)_
- `na_tokens` — Extra missing markers (comma-separated) _(field)_
- `fill_value` — Fill value (used by the Constant strategy) _(field)_
- `n_neighbors` — Neighbours (KNN) _(field)_
- `weights` — KNN weighting _(field)_

## Output

- Imputed CSV (text)

## Query parameters

Open the tool pre-filled and auto-run via URL:

- `input` — CSV
- `strategy` — Imputation strategy
- `header` — First row is a header (kept, used for column names)
- `delimiter` — Delimiter
- `columns` — Columns to impute (blank = all)
- `na_tokens` — Extra missing markers (comma-separated)
- `fill_value` — Fill value (used by the Constant strategy)
- `n_neighbors` — Neighbours (KNN)
- `weights` — KNN weighting

Example: `https://gizza.ai/tools/missing-value-imputer/?input=name%2Cage%2Ccity%0AAlice%2C30%2CNYC%0ABob%2C%2CLA%0ACarol%2C40%2C&strategy=mean&header=true&delimiter=comma&columns=age%2Ccity&na_tokens=NA%2Cnull%2C%3F&fill_value=0&n_neighbors=5&weights=uniform`

---

## Fill missing values in a CSV

Paste a CSV with blank or `NA` cells and this tool fills them in locally in your
browser — **nothing is uploaded**. Pick the imputation strategy that fits your
data:

- **Mean** — replace blanks in a numeric column with the column average.
- **Median** — replace blanks with the middle value; robust to outliers.
- **Most frequent** — replace blanks with the column's most common value; works on
  text (categorical) columns too.
- **Constant** — write a fixed value (like `0` or `Unknown`) into every blank.
- **KNN** — estimate each blank from its *k* nearest rows using a nan-euclidean
  distance over the numeric columns, averaged uniformly or by inverse distance.

A cell counts as **missing** when it is empty after trimming, or equals one of the
extra markers you list under *missing markers* (for example `NA`, `null`, `?`).
Mean, median, and KNN only touch **numeric** columns (a column whose every present
value parses as a number); most-frequent and constant apply to any column.

### Worked example

With the default **Mean** strategy, this input:

```
name,age,city
Alice,30,NYC
Bob,,LA
Carol,40,
```

becomes:

```
name,age,city
Alice,30,NYC
Bob,35,LA
Carol,40,
```

`age` is numeric, so Bob's blank is filled with the mean of `30` and `40` — `35`.
The blank `city` for Carol is left untouched because `city` is a text column and
mean/median only impute numeric data; switch to **Most frequent** or **Constant**
to fill it.

### FAQ

<details>
<summary>Which columns get imputed?</summary>

By default every applicable column. Type a comma-separated list under **Columns to
impute** to restrict it — use header names (like `age,income`) when the first row
is a header, or 1-based indexes (like `2,3`). Columns you don't list are copied
through unchanged.

</details>

<details>
<summary>What counts as a missing value?</summary>

A cell is missing when it's empty or whitespace-only after trimming. To also treat
sentinel strings as missing, list them under **Extra missing markers** —
`NA,null,?` for example. Matching is exact and case-sensitive, so `NA` is missing
but `na` is not unless you add it too.

</details>

<details>
<summary>How does the mean/median differ from most-frequent and constant?</summary>

**Mean** and **median** are numeric: they only fill columns whose present values
are all numbers, and they skip text columns entirely. **Most frequent** picks the
most common existing value (ties go to the first one seen) and works on any column,
including categories. **Constant** ignores the data and writes whatever you put in
**Fill value** into every blank.

</details>

<details>
<summary>How does KNN imputation work here?</summary>

For each missing numeric cell, the tool measures the distance from that row to
every other row that *has* a value in the column, using a nan-euclidean metric over
the numeric columns (it scales by the number of shared present features). It then
averages the `n_neighbors` closest rows — a plain average with **Uniform** weights,
or an inverse-distance weighted average with **Distance**. Rows with no comparable
neighbour fall back to the column mean.

</details>

<details>
<summary>Is my data uploaded anywhere?</summary>

No. The whole imputation runs locally with WebAssembly; your CSV never leaves your
browser.

</details>

### Limits & edge cases

- Mean, median, and KNN need numbers: a column with any non-numeric present value
  is treated as text and left unchanged by those strategies. Use most-frequent or
  constant for categorical data.
- `NaN` and `inf` are **not** valid numbers here — a column containing them is
  treated as text, not numeric.
- Rows may have different column counts; short rows are padded with empty (missing)
  cells to the widest row before imputing.
- Turn off **First row is a header** for files with no header row; then column
  selection must use 1-based indexes and row 1 is imputed like any other.
- KNN with no usable neighbour (e.g. every other row also blank in that column)
  falls back to the column mean, and to nothing if the column is entirely empty.
- Everything runs in memory, so very large files are bounded by your browser's
  available memory.

## Related tools

- [Amazon Order Analyzer](https://gizza.ai/tools/amazon-order-analyzer/): Paste an Amazon order-history CSV export to summarize total spend by month, top items, and category breakdowns. Browser-only, private, with Markdown or JSON output.
- [Avro to JSON Converter](https://gizza.ai/tools/avro-to-json/): Decode Apache Avro Object Container Files (.avro / OCF) to JSON, NDJSON, or the embedded schema — no .avsc needed, free and private in your browser.
- [Reconcile bank statement and ledger CSVs](https://gizza.ai/tools/bank-statement-reconcile/): Match bank-statement CSV rows to ledger rows by date, signed amount, and fuzzy memo similarity, with unmatched and suggested matches.
- [Bencode decoder](https://gizza.ai/tools/bencode-decoder/): Decode bencode (the BitTorrent / .torrent serialization format) into readable JSON, and re-encode JSON back into canonical bencode — in your browser. Nothing is uploaded.
- [Budget Planner](https://gizza.ai/tools/budget-planner/): Plan a monthly budget from take-home pay: 50/30/20 needs/wants/savings targets with custom splits, or a zero-based plan showing what's left to allocate.
