# Merge & Dedup Datasets — Combine, Remove Duplicates, Diff (`steadyscrape/merge-dedup-datasets`) Actor

Merge Apify datasets and CSV, JSON or Excel files into one, deduplicate by key fields (case, accents, URL, email and phone aware), keep only new items since the last run, or diff two runs: new, changed and removed rows. Export to JSON, CSV or Excel, or via API.

- **URL**: https://apify.com/steadyscrape/merge-dedup-datasets.md
- **Developed by:** [Steady Scrape](https://apify.com/steadyscrape) (community)
- **Categories:** Developer tools, Automation, Integrations
- **Features:** Limited permissions
- **Stats:** 2 total users, 1 monthly users, 100.0% runs succeeded, 0 bookmarks
- **User rating**: No ratings yet

## Pricing

from $0.04 / 1,000 row writtens

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/actors/running/actors-in-store.md#pay-per-event

## What's an Apify Actor?

An Actor is a serverless cloud program that runs on the Apify platform. It has two run modes.
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.

Apify vocabulary and the platform model are defined once, in the agent quickstart at https://apify.com/agents.md.

## 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.

Do not guess an integration path. Every one of them is in the agent quickstart at https://apify.com/agents.md: the Apify MCP server, Agent Skills with the Apify CLI, the JavaScript and Python clients, the REST API, and the account-free path for an agent with no human to sign in. It also carries the rule on stating cost before the first paid run.

For examples already wired to this Actor's own input schema, see the [API](#api) section below.

Each client library has reference documentation the quickstart does not restate: [JavaScript/TypeScript](https://docs.apify.com/api/client/js/docs.md) (`npm install apify-client`) and [Python](https://docs.apify.com/api/client/python/docs.md) (`pip install apify-client`).

# README

## Merge & Dedup Datasets — combine datasets, remove duplicates, diff runs

**Merge datasets** from your Apify runs and data files (CSV, TSV, JSON, JSON Lines, Excel) into one dataset and
**remove duplicates** by the fields you name — compared the way people mean them: ignoring case, spaces and accents,
links compared without `www`, trailing slashes or `utm_*` tags, emails in any case, phones by their digits. Run it
again later in **only-new** mode to get just the rows you have not seen before, or in **diff** mode to see what is
new, what changed (and from what) and what disappeared since the last run.

- **Every source in one place**: pick datasets in the form, paste file links (a shared Google Sheet works), or pick a
  key-value store whose records are data files. Gzipped files are unpacked.
- **Duplicates by key fields, normalised per field**: `website` compared as a link, `email` as an email, `name`
  ignoring case and accents — or no key at all, to drop only rows identical in every field.
- **You choose which duplicate stays**: the first seen, the last seen, the one with most fields filled, or the newest by
  a date field — and optionally **fill its empty fields from the others**, so three partial rows become one full row.
- **Each row says where it came from** (`_source`: the dataset, the file link with any token masked, or the record).
- **Only new rows since the last run**, for a scraper on a schedule: the seen keys are kept under a history name you
  choose, so one Actor serves many monitors.
- **A diff between runs**: each row tagged `new`, `changed` (with the changed fields and their previous values) or
  `removed`; the fields a scraper stamps on every run (`scrapedAt`…) are ignored, and you can add your own.
- **Light clean-up on the way**: rename columns so differently named sources line up, keep or drop fields, flatten
  nested objects into spreadsheet columns, and filter rows (equals, contains, is empty, greater than, less than).
- **A source that cannot be read costs nothing**: a dead link, a web page instead of a file, a PDF, a file over your
  size limit, an empty dataset — the run goes on with the other sources and the summary says what happened to each.

### Use cases

- **Merge the runs of one scraper over many searches** into one list without the items several searches found.
- **Get only the new items of a scheduled scrape**: new job ads, new posts, new listings, new reviews since yesterday.
- **Monitor changes**: prices, ranks, stock, ratings — what moved since the last run, and from what value.
- **Combine leads from several sources** (a Maps scrape, a directory, a CSV from a client) and keep one row per website
  or email, with the fullest data.
- **Clean an export before it goes to a spreadsheet or a CRM**: renamed, filtered, flattened, without duplicates.

### How to merge datasets and remove duplicates

| field | what it does |
|---|---|
| `datasets` | Pick the datasets to merge (your runs' results, imports, earlier merges). Picking is what lets the run read them; through the API, give dataset ids or `username~name`. |
| `fileUrls` | Links to CSV, TSV, JSON, JSON Lines or `.xlsx` files, gzipped or not. A Google Sheet link is read as its CSV export (the tab of the link); a Console link to a dataset is read as that dataset. |
| `keyValueStore`, `recordKeys` | Pick a key-value store and name its records that hold data files; with no names, every data record (not its `INPUT`, not its images). |
| `keyFields` | Rows with equal values in these fields are duplicates; dotted paths reach nested fields (`search.query`). Empty: rows identical in every field. |
| `normalize` | How key values are compared: `whitespace` (default), `case`, `accents`, `url`, `email`, `phone`. |
| `fieldNormalization` | A key field with its own comparison: `website` → `url`, `email` → `email`, `name` → `case, accents, whitespace`. |
| `keep` | Which duplicate stays: `first` (default), `last`, `mostFilled`, `newest` (with `dateField`). |
| `dateField` | The date compared for `newest`: ISO dates, written dates, epoch seconds or milliseconds. |
| `fillEmptyFields` | The row kept takes the values it lacks from the duplicates it replaces. |
| `sourceField` | The field that names each row's source (default `_source`; empty adds none). |
| `mode` | `merge` (default): every unique row. `onlyNew`: rows whose key no earlier run of the history saw. `diff`: new, changed and removed rows against the previous run. |
| `historyName` | One name per monitor (default `default`); runs with the same name share their history. |
| `diffIgnoreFields` | Fields that never make a row changed (default `scrapedAt`, `crawledAt`, `checkedAt`, `fetchedAt`). Add the fields your scraper rewrites on every run — a job's `position` in the results, signed `applyLinks` — or pick only the fields you watch with `pickFields`. |
| `includeUnchanged` | Diff mode also writes the rows that did not change, tagged `unchanged`. |
| `renameFields` | Renamed as each row is read, so keys and filters use one name across sources (`alpha-2` → `Code`). |
| `filters` | Rows must pass all of them: `[{"field": "rating", "operator": "greaterThan", "value": 4.5}]`. Operators `equals`, `notEquals`, `contains`, `notContains` (any case), `isEmpty`, `isNotEmpty`, `greaterThan`, `lessThan` (numbers, also inside text such as `"$1,299"`, or dates). |
| `pickFields`, `omitFields` | Keep only, or leave out, these fields of the rows written. |
| `flatten` | Nested objects and lists become dotted columns (`address.city`, `images.0.url`). |
| `maxRows` | Most rows read from all sources together (default 1,000,000). |
| `maxFileMegabytes` | A larger file or record is reported and not read (default 100). |

### Examples with our own scrapers

**Merge Google Jobs runs into one list of jobs.** Run [Google Jobs Scraper](https://apify.com/steadyscrape/google-jobs-scraper)
for each search or each day, then pick their datasets. Two runs of the same search a day apart, 11 and 10 rows, merged
into 18: the 3 jobs both runs found appear once, and each row says which run found it.

```json
{
    "datasets": ["<Monday's run>", "<Tuesday's run>"],
    "keyFields": ["jobId"]
}
```

**Only the new posts of the businesses you follow.** Schedule
[Google Maps Business Posts Scraper](https://apify.com/steadyscrape/google-maps-business-posts-scraper), then this Actor
on its dataset. The first run wrote all 28 posts; a run five days later read 28 and wrote the 10 nobody had seen.

```json
{
    "datasets": ["<the latest posts run>"],
    "keyFields": ["postId"],
    "mode": "onlyNew",
    "historyName": "austin-dentists"
}
```

**What moved on a local rank grid.** Compare each run of
[Google Maps Rank Tracker](https://apify.com/steadyscrape/google-maps-rank-tracker) with the previous one: of 26 grid
points, 11 came back changed, each with its previous rank.

```json
{
    "datasets": ["<the latest grid run>"],
    "keyFields": ["rowType", "row", "col"],
    "pickFields": ["rowType", "row", "col", "rank", "inTop3"],
    "mode": "diff",
    "historyName": "swish-dentist"
}
```

```json
{ "rowType": "point", "row": 2, "col": 1, "rank": 5, "inTop3": false, "_change": "changed", "_changedFields": ["rank", "inTop3"], "_previousValues": { "rank": 3, "inTop3": true }, "_source": "dataset <the grid run's dataset id>" }
```

### Output

The dataset holds the unique rows with their own fields, after renames, picks and flattening, plus:

| field | what it holds |
|---|---|
| `_source` | Where the row came from: `dataset <id>`, the file link (tokens, signatures and keys masked as `***`) or `record <store>/<key>`. Named by `sourceField`; null on a removed row. |
| `_change` | Diff mode: `new`, `changed`, `unchanged` (with `includeUnchanged`) or `removed`. |
| `_changedFields` | Diff mode: the top-level fields whose values changed. |
| `_previousValues` | Diff mode: the previous value of each changed field. |

In only-new and diff modes a row with no value in any key field cannot be followed from run to run: it is left out
and counted as a row without a key. A removed row is the row as the previous run wrote it. Removed rows are told only when every source was read whole: a
row of a source that could not be read this time is not called removed.

The key-value store record `SUMMARY` gives each source's rows read, skipped and filtered out with its status (`ok`,
`unreadable`, `empty`, `not_tabular`, `too_large`, `not_read`) and reason, then the duplicates dropped, the rows
without a key, the rows written as unique, new, changed, unchanged or removed, the rows already seen, and the history
saved. The run's status message says the same in one line.

### Pricing

Pay per event, no start fee:

| event | price | when |
|---|---|---|
| `item` | US$0.00004 | each row written (unique, new, changed or removed) |
| `rows-read-1k` | US$0.002 | each started block of 1,000 rows read from your sources |

Merging three runs of 10,000 rows into 25,000 unique rows costs 30 × US$0.002 + 25,000 × US$0.00004 = **US$1.06**.
A daily only-new check of a 2,000-row scrape that finds 50 new rows costs 2 × US$0.002 + 50 × US$0.00004 = **US$0.006**.
Sources that cannot be read or are empty, rows filtered out, duplicates dropped, rows already seen and unchanged rows
(unless you ask for them) are free. Your spending limit is respected before reading and while writing: the rows the
limit keeps from being written stay new for the next only-new or diff run.

### Limits

- **Memory and speed**: the unique rows are held in memory until they are written. Measured on Apify: 100,002 rows of
  2.3 KB (Maps posts) from three files, 66,668 of them unique, took 258 MB and 80 s with the default 512 MB, and 14 s
  with 1 GB (more memory also means more CPU). Diff mode holds the previous snapshot too, so it fits about half as many
  rows; rows of 12–16 KB (job ads with full descriptions) take several times more. Give the run more memory for more
  rows. When memory runs short the run stops reading, writes what it holds and says so; it does not fail.
- A JSON document or an Excel workbook is parsed whole: one that would not fit in memory is reported as too large
  (CSV, TSV and JSON Lines are streamed, whatever their size). Excel: the first sheet; `.xls` is not read.
- A history keeps ~17 bytes per seen key (a million keys ≈ 17 MB) and, for diff, the rows as written. Changing the key
  fields of a history starts it again, and the run says so. Histories live in a key-value store of your account named
  `steadyscrape-merge-dedup-datasets-state`; delete a history by deleting its `<name>--seen` or `<name>--snapshot` record.
- Private Apify datasets and stores are readable only when picked in the form (or passed through the API). A private
  file link answers 401 or 403: share it publicly or upload it to a dataset.

### Your data and your responsibility

The Actor reads only what you give it: the datasets and stores you pick, and each file link once, on your behalf. It
never connects to private, local or reserved networks (cloud metadata addresses included), follows at most 5
redirects, and keeps nothing besides the history you name. Merge only data you have the right to use: personal data in
a merged list (emails, phones, names) stays subject to the GDPR, CCPA and similar laws wherever it came from. This is
an independent tool by Steady Scrape, not affiliated with or endorsed by Google (Sheets), Microsoft (Excel) or Dropbox.

Questions, a source it should read, or a comparison it should make: open an issue on the Actor's page.

# Actor input Schema

## `datasets` (type: `array`):

Pick the datasets to merge: the results of your scraper runs, imports, earlier merges. Picking a dataset here is what lets this run read it. Through the API, give dataset ids (or username~name).

## `fileUrls` (type: `array`):

Links to data files: CSV, TSV, JSON, JSON Lines, Excel .xlsx, also gzipped. A shared Google Sheet link is read as its CSV export; an Apify Console link to a dataset is read as that dataset.

## `keyValueStore` (type: `string`):

Pick a key-value store whose records are data files (CSV, JSON, Excel…). Its records named below are read; with none named, every data record (not its INPUT nor its images).

## `recordKeys` (type: `array`):

The keys of the records to read from the store picked above. Leave empty to read every data record.

## `keyFields` (type: `array`):

Rows with the same values in these fields are duplicates. Dotted paths reach into nested objects (search.query, address.city). Leave empty to drop only rows identical in every field.

## `normalize` (type: `array`):

How key values are compared. Whitespace trims and squeezes spaces; case ignores upper/lower case; accents ignores diacritics (é = e); url compares links whatever their scheme, www, trailing slash or tracking parameters (utm\_\*, fbclid, gclid…); email lower-cases and drops mailto:; phone keeps digits only.

## `fieldNormalization` (type: `array`):

Key fields that need their own normalisation: the field, then the names from the list above separated by commas (website → url; email → email; name → case, accents, whitespace). Fields not named here use the setting above.

## `keep` (type: `string`):

First seen follows the order of the sources (datasets, then file links, then records) and of the rows in each.

## `dateField` (type: `string`):

The field to compare when keeping the newest: ISO dates, written dates and epoch seconds or milliseconds are understood.

## `fillEmptyFields` (type: `boolean`):

The row kept takes the values of fields it lacks or has empty (null, blank, \[]) from the duplicates it replaces: one fuller row out of several partial ones.

## `sourceField` (type: `string`):

Each row written says where it came from (dataset id, file link with any token masked, or record) in this field. Clear it to add no field.

## `mode` (type: `string`):

Merge writes every unique row. Only new writes the unique rows whose key no earlier run of the same history saw. Diff compares with the previous run of the same history and writes each row as new, changed (with the fields that changed and their previous values) or removed.

## `historyName` (type: `string`):

Runs with the same history name share their seen keys and snapshot; use one name per monitor (a search, a client, a grid). Letters, digits, dots, dashes and underscores. Kept in a store of your account named steadyscrape-merge-dedup-datasets-state.

## `diffIgnoreFields` (type: `array`):

Top-level fields that never make a row changed, such as the time a scraper read it.

## `includeUnchanged` (type: `boolean`):

Write the rows that did not change too, tagged unchanged, for a full picture of each run.

## `renameFields` (type: `array`):

Renamed as each row is read, so key fields and filters can use the new names across sources with different column names. A dotted path moves a nested value to a top-level field.

## `filters` (type: `array`):

Rows must pass every filter to be kept, e.g. \[{"field": "rating", "operator": "greaterThan", "value": 4.5}]. Operators: equals, notEquals, contains, notContains (any case), isEmpty, isNotEmpty, greaterThan, lessThan (numbers, also inside text such as "$1,299", or dates such as "2026-01-01").

## `pickFields` (type: `array`):

Fields written to the output, dotted paths allowed. Empty keeps every field.

## `omitFields` (type: `array`):

Fields dropped from the output, dotted paths allowed.

## `flatten` (type: `boolean`):

Nested objects and lists become dotted columns (address.city, images.0.url), ready for a spreadsheet.

## `maxRows` (type: `integer`):

Reading stops after this many rows from all sources together.

## `maxFileMegabytes` (type: `integer`):

A larger file or record is reported and not read.

## Actor input object example

```json
{
  "fileUrls": [
    "https://raw.githubusercontent.com/datasets/country-list/main/data.csv",
    "https://cdn.jsdelivr.net/gh/lukes/ISO-3166-Countries-with-Regional-Codes@master/all/all.json"
  ],
  "keyFields": [
    "Code"
  ],
  "normalize": [
    "whitespace"
  ],
  "keep": "first",
  "fillEmptyFields": true,
  "sourceField": "_source",
  "mode": "merge",
  "historyName": "default",
  "diffIgnoreFields": [
    "scrapedAt",
    "crawledAt",
    "checkedAt",
    "fetchedAt"
  ],
  "includeUnchanged": false,
  "renameFields": [
    {
      "key": "alpha-2",
      "value": "Code"
    },
    {
      "key": "name",
      "value": "Name"
    }
  ],
  "filters": [],
  "flatten": false,
  "maxRows": 1000000,
  "maxFileMegabytes": 100
}
```

# Actor output Schema

## `rows` (type: `string`):

No description

## `summary` (type: `string`):

No description

# 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 = {
    "fileUrls": [
        "https://raw.githubusercontent.com/datasets/country-list/main/data.csv",
        "https://cdn.jsdelivr.net/gh/lukes/ISO-3166-Countries-with-Regional-Codes@master/all/all.json"
    ],
    "keyFields": [
        "Code"
    ],
    "fillEmptyFields": true,
    "renameFields": [
        {
            "key": "alpha-2",
            "value": "Code"
        },
        {
            "key": "name",
            "value": "Name"
        }
    ]
};

// Run the Actor and wait for it to finish
const run = await client.actor("steadyscrape/merge-dedup-datasets").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 = {
    "fileUrls": [
        "https://raw.githubusercontent.com/datasets/country-list/main/data.csv",
        "https://cdn.jsdelivr.net/gh/lukes/ISO-3166-Countries-with-Regional-Codes@master/all/all.json",
    ],
    "keyFields": ["Code"],
    "fillEmptyFields": True,
    "renameFields": [
        {
            "key": "alpha-2",
            "value": "Code",
        },
        {
            "key": "name",
            "value": "Name",
        },
    ],
}

# Run the Actor and wait for it to finish
run = client.actor("steadyscrape/merge-dedup-datasets").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 '{
  "fileUrls": [
    "https://raw.githubusercontent.com/datasets/country-list/main/data.csv",
    "https://cdn.jsdelivr.net/gh/lukes/ISO-3166-Countries-with-Regional-Codes@master/all/all.json"
  ],
  "keyFields": [
    "Code"
  ],
  "fillEmptyFields": true,
  "renameFields": [
    {
      "key": "alpha-2",
      "value": "Code"
    },
    {
      "key": "name",
      "value": "Name"
    }
  ]
}' |
apify call steadyscrape/merge-dedup-datasets --silent --output-dataset

```

## MCP server setup

```json
{
    "mcpServers": {
        "apify": {
            "type": "http",
            "url": "https://mcp.apify.com/?tools=fetch-actor-details,steadyscrape/merge-dedup-datasets"
        }
    }
}
```

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/NtbeqkSS9CwpLnPYW/builds/gWvh3L6cNBYPlvmrl/openapi.json
