# Dataset Cleaner & Deduplicator (`luminous_i/dataset-cleaner-deduplicator`) Actor

Clean, normalize and deduplicate any dataset: field names, whitespace, empty values, numbers, plus exact and fuzzy duplicate removal.

- **URL**: https://apify.com/luminous\_i/dataset-cleaner-deduplicator.md
- **Developed by:** [Steve](https://apify.com/luminous_i) (community)
- **Categories:** Other, Automation
- **Stats:** 2 total users, 1 monthly users, 100.0% runs succeeded, 0 bookmarks
- **User rating**: No ratings yet

## Pricing

from $0.30 / 1,000 item cleaneds

This Actor is paid per event. You are not charged for the Apify platform usage, but only a fixed price for specific events.

Learn more: https://docs.apify.com/platform/actors/running/actors-in-store#pay-per-event

## What's an Apify Actor?

Actors are web data automations that power AI and operations. They run on the Apify platform to scrape websites, process data, connect APIs, and automate workflows.
In Batch mode, an Actor accepts a well-defined JSON input, performs an action which can take anything from a few seconds to a few hours,
and optionally produces a well-defined JSON output, datasets with results, or files in key-value store.
In Standby mode, an Actor provides a web server which can be used as a website, API, or an MCP server.
Actors are written with capital "A".

## How to integrate an Actor?

If asked about integration, you help developers integrate Actors into their projects.
You adapt to their stack and deliver integrations that are safe, well-documented, and production-ready.
The best way to integrate Actors is as follows.

- **AI agents and MCP clients** — the [Apify MCP server](https://docs.apify.com/integrations/mcp.md) at `https://mcp.apify.com` (remote, streamable HTTP, OAuth on first use).
- **Agentic workflows and local Actor development** — [Agent Skills](https://apify.com/.well-known/agent-skills/index.json) with the [Apify CLI](https://docs.apify.com/cli/docs.md): `npm install -g apify-cli`, then `apify login`.
- **JavaScript/TypeScript projects** — the official [JS/TS client](https://docs.apify.com/api/client/js/docs.md): `npm install apify-client`.
- **Python projects** — the official [Python client](https://docs.apify.com/api/client/python/docs.md): `pip install apify-client`.
- **Any other language** — the [REST API](https://docs.apify.com/api/v2.md).

For usage examples, see the [API](#api) section below.

For more details, see Apify documentation as [Markdown index](https://docs.apify.com/llms.txt) and [Markdown full-text](https://docs.apify.com/llms-full.txt).

# README

## Dataset Cleaner & Deduplicator

Scraped data is messy. Field names arrive in three different casings, half the
values are `"N/A"` instead of empty, phone numbers carry random punctuation, and
the same company shows up four times under slightly different names.

This Actor takes any dataset and hands you back a clean one. Point it at the
output of any scraper, or paste your own JSON.

### What it fixes

| Problem | What you get back |
|---|---|
| `"First Name"`, `"firstName"`, `"FIRST_NAME"` | one consistent `first_name` key |
| `"  Jean   Dupont  "` | `"Jean Dupont"` |
| `"N/A"`, `"null"`, `"-"`, `"unknown"` | real `null` values |
| `"+33 (0)6 12.34-56 78"` | `"+330612345678"` |
| `"1 234,56"` and `"1,234.56"` | `1234.56` |
| `"Société Dupont"` vs `"SOCIETE DUPONT"` | one row, not two |

### Two ways to run it

**Chain it after a scraper.** Copy the Dataset ID from any finished run and paste
it into `inputDatasetId`. This is the common case: scrape, then clean.

**Paste data directly.** Drop a JSON array into `items` for a one-off cleanup.

### Deduplication

**Exact mode** compares values literally, case-insensitively. Pick which fields
identify a duplicate with `dedupeFields` — usually `email` or `url`. Leave it
empty to compare whole rows.

**Fuzzy mode** catches near-duplicates that exact matching misses. Set
`fuzzyField` to the column that identifies a record, typically a company or
person name.

The `fuzzyThreshold` controls how aggressive matching is:

| Threshold | Behaviour |
|---|---|
| 95+ | Only trivial variants: casing, accents, extra spaces |
| 90 | Safe default — the same entity written slightly differently |
| 80 | Catches suffix differences like `SARL`, `Ltd`, `Inc` |
| Below 80 | Aggressive. Expect false positives |

Legal suffixes cost more similarity than they look: `Societe Dupont` and
`SOCIETE DUPONT SARL` score just under 85, so they stay separate at the default
threshold. Lower `fuzzyThreshold` to 80 if you want those merged.

Accents and casing are normalized before comparison, so `Société Dupont` and
`SOCIETE DUPONT` always match regardless of threshold.

### Output

Cleaned records go to the default dataset. A `STATS` record is written to the
key-value store:

```json
{
  "inputItems": 5000,
  "outputItems": 4212,
  "duplicatesRemoved": 703,
  "droppedIncomplete": 85,
  "dedupeMode": "fuzzy"
}
```

### Notes

Fuzzy deduplication is quadratic in the worst case. Above 50,000 rows the Actor
automatically falls back to exact matching rather than burning your compute
budget. Records are compared inside blocks of similar values, so real-world runs
stay fast well below that ceiling.

Field names are normalized before `requiredFields`, `dedupeFields` and
`fuzzyField` are applied — so write them in snake\_case, or just use the original
name and let the Actor normalize it for you. If you turn `normalizeFieldNames`
off, these three settings are matched against your original keys instead, exactly
as they appear in the data.

# Actor input Schema

## `inputDatasetId` (type: `string`):

ID of a dataset produced by any other Actor. Leave empty if you paste data below.

## `items` (type: `array`):

Array of JSON objects. Only used when no Dataset ID is provided.

## `normalizeFieldNames` (type: `boolean`):

Turns 'First Name', 'firstName' and 'FIRST\_NAME' into a single 'first\_name' key.

## `trimWhitespace` (type: `boolean`):

Removes leading and trailing spaces, collapses repeated spaces.

## `normalizeEmptyValues` (type: `boolean`):

Converts 'N/A', 'null', '-' and 'unknown' into real null values.

## `lowercaseEmails` (type: `boolean`):

Converts all email fields to lowercase so 'John@X.com' and 'john@x.com' are treated as one address.

## `normalizePhones` (type: `boolean`):

Strips spaces, dots and dashes while keeping the international prefix.

## `coerceNumbers` (type: `boolean`):

Turns '1 234,56' and '1,234.56' into real numeric values. Handles both European and US formats.

## `dropEmptyFields` (type: `boolean`):

Shrinks output size by removing keys with no value.

## `requiredFields` (type: `array`):

Any row missing one of these fields is discarded.

## `dedupeMode` (type: `string`):

Exact compares values literally. Fuzzy catches near-duplicates like 'Société Dupont' and 'SOCIETE DUPONT', whatever the accents or casing.

## `dedupeFields` (type: `array`):

Leave empty to compare the entire row.

## `fuzzyField` (type: `string`):

Name of the field to match on, for example 'company\_name'.

## `fuzzyThreshold` (type: `integer`):

50 to 100. Above 95 is strict, below 80 becomes aggressive. 90 is a safe default; use 80 to also merge legal suffixes like SARL, Ltd or Inc.

## Actor input object example

```json
{
  "inputDatasetId": "aBcDeFgHiJkLmNoPq",
  "items": [],
  "normalizeFieldNames": true,
  "trimWhitespace": true,
  "normalizeEmptyValues": true,
  "lowercaseEmails": true,
  "normalizePhones": true,
  "coerceNumbers": false,
  "dropEmptyFields": false,
  "requiredFields": [],
  "dedupeMode": "exact",
  "dedupeFields": [],
  "fuzzyThreshold": 90
}
```

# Actor output Schema

## `cleanedItems` (type: `string`):

Normalized and deduplicated records, one per row.

## `stats` (type: `string`):

Input/output counts, duplicates removed and incomplete rows dropped.

# API

You can run this Actor programmatically using our API. Below are code examples in JavaScript, Python, and CLI, as well as the OpenAPI specification and MCP server setup.

## JavaScript example

```javascript
import { ApifyClient } from 'apify-client';

// Initialize the ApifyClient with your Apify API token
// Replace the '<YOUR_API_TOKEN>' with your token
const client = new ApifyClient({
    token: '<YOUR_API_TOKEN>',
});

// Prepare Actor input
const input = {
    "items": []
};

// Run the Actor and wait for it to finish
const run = await client.actor("luminous_i/dataset-cleaner-deduplicator").call(input);

// Fetch and print Actor results from the run's dataset (if any)
console.log('Results from dataset');
console.log(`💾 Check your data here: https://console.apify.com/storage/datasets/${run.defaultDatasetId}`);
const { items } = await client.dataset(run.defaultDatasetId).listItems();
items.forEach((item) => {
    console.dir(item);
});

// 📚 Want to learn more 📖? Go to → https://docs.apify.com/api/client/js/docs

```

## Python example

```python
from apify_client import ApifyClient

# Initialize the ApifyClient with your Apify API token
# Replace '<YOUR_API_TOKEN>' with your token.
client = ApifyClient("<YOUR_API_TOKEN>")

# Prepare the Actor input
run_input = { "items": [] }

# Run the Actor and wait for it to finish
run = client.actor("luminous_i/dataset-cleaner-deduplicator").call(run_input=run_input)

# Fetch and print Actor results from the run's dataset (if there are any)
print(f"💾 Check your data here: https://console.apify.com/storage/datasets/{run.default_dataset_id}")
for item in client.dataset(run.default_dataset_id).iterate_items():
    print(item)

# 📚 Want to learn more 📖? Go to → https://docs.apify.com/api/client/python/docs/quick-start

```

## CLI example

```bash
echo '{
  "items": []
}' |
apify call luminous_i/dataset-cleaner-deduplicator --silent --output-dataset

```

## MCP server setup

```json
{
    "mcpServers": {
        "apify": {
            "type": "http",
            "url": "https://mcp.apify.com/?tools=fetch-actor-details,luminous_i/dataset-cleaner-deduplicator"
        }
    }
}

```

The hosted server signs you in with OAuth on first connect, so no API token belongs in this config. Clients without OAuth support can send an `Authorization: Bearer <APIFY_API_TOKEN>` header instead, using a token from API & Integrations in Apify Console (https://console.apify.com/settings/integrations).

## OpenAPI specification

Download the OpenAPI definition: https://api.apify.com/v2/actors/mqbfhwI6LdKhIgHJW/builds/3yNOzOAIAyMsMzuYQ/openapi.json
