# Merge Datasets & Remove Duplicates – Join & Dedupe CSV, Excel (`gazidev/dataset-merge-dedupe`) Actor

Merge Apify datasets, CSV and Excel files into one table and remove duplicates by any fields. Join two tables by key (VLOOKUP: left, inner, full, anti), compare two runs (added, removed, changed), or get only new items since the last run. Export CSV, XLSX, JSON. $0.20 per 1,000 rows.

- **URL**: https://apify.com/gazidev/dataset-merge-dedupe.md
- **Developed by:** [Cemal Atakli](https://apify.com/gazidev) (community)
- **Features:** Limited permissions
- **Stats:** 2 total users, 1 monthly users, 100.0% runs succeeded, 0 bookmarks
- **User rating**: No ratings yet

## Pricing

from $0.20 / 1,000 row delivereds

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 datasets and remove duplicates: join, dedupe and compare Apify datasets, CSV and Excel

**Dataset Merge & Dedupe** puts several Apify datasets, CSV, Excel or JSON files into **one clean table** and **removes duplicates**. It can also **join two tables by a key** (like VLOOKUP or a SQL join), **compare two runs** (added, removed and changed rows) and return **only new items** since the last run.

No code and a short input. You pay **$0.20 per 1,000 delivered rows**. Removed duplicates are not charged as rows.

### What it does

| Mode | Result |
|---|---|
| **Merge** (default) | All datasets and files in one table, duplicates removed |
| **Join** | Columns of a second table added by key: `left`, `inner`, `full` or `anti` (rows without a match) |
| **Compare** | `added`, `removed` and `changed` rows between an old and a new table, with the old values |

- **Remove duplicates** by any fields (`url`, or `name` + `city`), or by the whole row. Upper/lower case and extra spaces are ignored by default.
- **Choose which duplicate stays:** first, last, most complete, or *combine* (empty fields are filled from the other duplicates).
- **Only new items:** remembers delivered rows between runs, so a scheduled scraper gives you only new listings, jobs or leads.
- **Similar column names are matched:** `E-mail`, `email` and `EMAIL ` from different files become one column.
- **Inputs:** Apify datasets, CSV, TSV, XLSX, XLS, XLSB, ODS, JSON, JSON Lines. Links from Google Sheets, Google Drive, Dropbox, OneDrive and GitHub work when they are public.
- **Output:** dataset rows (JSON, CSV, Excel, API) and, if you want, one CSV, XLSX or JSON file.
- **Limited permissions:** the Actor only reads the datasets you pick.

### Use cases

- Merge the results of five Google Maps runs and keep one row per `placeId`
- Combine CSV files or merge Excel files from several people into one list
- Add CRM fields to scraped leads by e-mail or domain (VLOOKUP for datasets)
- Find leads that are **not** in your customer list yet (anti join)
- See which prices changed, and which products are new or gone, between yesterday's and today's run
- Get only new job ads or property listings from a daily scraper

### Input examples

**Merge and remove duplicates** (the 1-click example: two versions of the public Palmer penguins table)

```json
{
  "mode": "merge",
  "fileUrls": [
    "https://raw.githubusercontent.com/mwaskom/seaborn-data/master/penguins.csv",
    "https://raw.githubusercontent.com/allisonhorst/palmerpenguins/main/inst/extdata/penguins.csv"
  ],
  "dedupeFields": ["species", "island", "bill_length_mm", "bill_depth_mm", "flipper_length_mm", "body_mass_g"],
  "keep": "mostComplete",
  "limit": 100
}
```

**Join (VLOOKUP)**

```json
{
  "mode": "join",
  "datasetIds": ["YOUR_LEADS_DATASET_ID"],
  "secondFileUrls": ["https://example.com/crm-export.csv"],
  "keyFields": ["email"],
  "secondKeyFields": ["contact_email"],
  "secondFields": ["owner", "stage"],
  "joinType": "left"
}
```

**Compare two runs**

```json
{
  "mode": "compare",
  "datasetIds": ["OLD_RUN_DATASET_ID"],
  "secondDatasetIds": ["NEW_RUN_DATASET_ID"],
  "keyFields": ["sku"],
  "ignoreFields": ["scrapedAt"]
}
```

**Only new items after every scraper run:** in your scraper open *Integrations → Connect Actor*, choose this Actor and use

```json
{
  "datasetIds": ["{{resource.defaultDatasetId}}"],
  "dedupeFields": ["url"],
  "onlyNewItems": true,
  "stateStoreName": "my-job-alerts"
}
```

### Output examples

Merge:

```json
{"species": "Adelie", "island": "Torgersen", "bill_length_mm": 39.1, "bill_depth_mm": 18.7, "flipper_length_mm": 181,
 "body_mass_g": 3750, "sex": "male", "year": 2007, "_source": "https://raw.githubusercontent.com/allisonhorst/palmerpenguins/main/inst/extdata/penguins.csv"}
```

Compare:

```json
{"_change": "changed", "_changedFields": ["price"], "_before": {"price": 10}, "sku": 1, "price": 12}
```

Join adds `_match` (`both`, `left`, `right`) in left and full joins. The `OUTPUT` record holds the run summary: rows read, duplicates removed, matched / unmatched or added / removed / changed counts, each source with its status, the file link, warnings and charges.

### Pricing (pay per event)

| Event | Price |
|---|---|
| Row delivered | **$0.0002** ($0.20 per 1,000) |
| 1,000 source rows scanned | $0.002 |
| Export file (CSV / XLSX / JSON) | $0.003 |
| Actor start | $0.00005 |

- The 1-click example (688 rows read, 100 delivered) costs about **$0.022**.
- Merging 10,000 rows into 8,000 unique rows costs about **$1.62**.
- A daily "only new" run over 20,000 rows with 100 new ones costs about **$0.06**.

Duplicates, already seen rows, failed sources and invalid input are not charged as rows. If you set a maximum cost per run, the Actor stops cleanly at that amount.

| Actor (Apify Store, Nov 2026) | Price per row |
|---|---|
| **This Actor** | **$0.0002** |
| tidydata/merge-dedupe-datasets | $0.00025 + $0.005 per file |
| saliga/dataset-merge-dedupe | $0.0005 |
| humble-echidna/dataset-transform | $0.001 |
| lukaskrivka/dedup-datasets-limited-permissions | free |

### Rules and limits

- **Merge with `keep: first`** streams the data. Other `keep` choices hold the unique rows in memory.
- **Limit of 500,000 rows** in memory for: the second table of a join, the first table of a comparison, and unique rows when `keep` is not `first`. Wide rows may need more memory than the default 512 MB. The run tells you when that happens.
- **Join and compare need complete tables.** If a lookup table cannot be read, or your maximum cost is reached while it is read, the run fails and delivers no rows, because the result would be wrong. Rows already scanned are charged ($0.002 per 1,000).
- **Wrong key names** stop the run before any row is delivered.
- Rows whose key fields are all empty are never treated as duplicates and never match in a join.
- A joined row uses the first match by default. Choose *All matches* for SQL behaviour, which can create many rows.
- Compare without `keyFields` finds only added and removed rows. Both tables then need the same columns.
- In compare mode a repeated key is used once (the first row). `5`, `5.0` and `"5"` are equal, and so are empty and missing values.
- Big JSON arrays: use JSON Lines or CSV when a file is larger than about 10% of the run's memory.
- File links must be public. Links to private or internal network addresses are refused.

### Use with AI agents / Apify MCP

Add the Actor to the [Apify MCP server](https://mcp.apify.com). An agent can run two scrapers, call this Actor with both dataset IDs, and read one deduplicated table. Small tables can be passed directly in `items` and `secondItems`.

### Related Actors

- [Dataset Filter & Transform](https://apify.com/gazidev/dataset-filter-transform): same price, for **filter rules, sorting, renaming, type conversion, text cleaning and split exports**. It has no join and no compare. Use it when you need to filter or reshape one table. Use this Actor to merge, join or compare tables.
- [Dataset Cloud Export](https://apify.com/gazidev/dataset-cloud-export): send a dataset to cloud storage
- [Spreadsheet to JSON](https://apify.com/gazidev/spreadsheet-to-json): convert Excel and CSV files

### FAQ

**How is this different from dataset-filter-transform?** This Actor joins two tables by key, compares two tables, matches similar column names, and can keep the last, the most complete or a combined duplicate. dataset-filter-transform has filter rules and field transformations instead.

**Can I merge more than two datasets?** Yes, add as many datasets and files as you need. In join and compare mode each table can also consist of several sources.

**How does "only new items" work?** A 12-byte hash of each delivered row's key is kept in the named key-value store. Up to 2 million keys are remembered. To start over, use another name.

**Does it change my datasets?** No. It only reads them and writes the result to the run's own dataset.

**Who owns the example data?** The Palmer penguins data is CC0 (Gorman et al., palmerpenguins). It is only used for the example.

# Actor input Schema

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

Merge: put all sources into one table and remove duplicates. Join: add columns from a second table by key (like VLOOKUP / SQL join). Compare: list added, removed and changed rows between two tables.

## `datasetIds` (type: `array`):

Datasets to merge, e.g. the output of several scraper runs. For join: the left table. For compare: the old version. In an integration use {{resource.defaultDatasetId}}.

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

Public links to CSV, TSV, XLSX, XLS, ODS, JSON or JSON Lines files. Google Sheets / Drive (shared with 'Anyone with the link'), Dropbox, OneDrive and GitHub links work. The example has two versions of the same public table (344 rows each).

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

Optional JSON array of objects, added to the datasets and files above. Handy for AI agents.

## `removeDuplicates` (type: `boolean`):

Merge mode: without fields below, rows that are identical in every field are removed. Join mode: duplicates are only removed when you list fields below.

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

E.g. 'url', or 'name' + 'city'. Empty = the whole row must match. Rows where all these fields are empty are always kept.

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

'Combine' keeps the first row and fills its empty fields from the later duplicates.

## `ignoreCase` (type: `boolean`):

'ACME Inc ' and 'acme inc' count as the same value (duplicates, join keys and compare keys).

## `onlyNewItems` (type: `boolean`):

Remembers every delivered row in a named key-value store and skips it in later runs. Made for scheduled scrapers.

## `stateStoreName` (type: `string`):

Name of the store with the remembered keys. Use a different name for each pipeline.

## `secondDatasetIds` (type: `array`):

Join: the lookup (right) table. Compare: the new version. Not used in merge mode, where all sources are merged.

## `secondFileUrls` (type: `array`):

CSV, Excel or JSON links for the second table.

## `secondItems` (type: `array`):

Optional JSON array of objects for the second table.

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

Fields that identify the same row in both tables, e.g. 'email' or 'sku'. Required for join. Compare without keys only finds added and removed rows.

## `secondKeyFields` (type: `array`):

Only when they have other names there, in the same order.

## `joinType` (type: `string`):

Left: all rows of table A. Inner: only rows with a match. Full: rows of both tables. Anti: rows of A that have no match in B.

## `joinMatches` (type: `string`):

First = one output row per row of A, like VLOOKUP. All = one output row per match, like SQL (can create many rows).

## `secondFields` (type: `array`):

Empty = all columns.

## `secondPrefix` (type: `string`):

Put before columns of the second table whose name also exists in table A.

## `ignoreFields` (type: `array`):

E.g. 'scrapedAt'. Changes in these fields do not count.

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

Off = only added, removed and changed rows.

## `matchColumnNames` (type: `boolean`):

'E-mail', 'email' and 'EMAIL ' from different sources become one column.

## `addSourceField` (type: `boolean`):

Adds the dataset ID or file name to each row (merge and join).

## `limit` (type: `integer`):

0 = no limit. When the limit is reached, reading stops.

## `exportFormat` (type: `string`):

Saves the result as a file in the key-value store. The link is in the OUTPUT record.

## `exportFileName` (type: `string`):

Without extension.

## `maxFileSizeMb` (type: `integer`):

Larger files are skipped.

## Actor input object example

```json
{
  "mode": "merge",
  "fileUrls": [
    "https://raw.githubusercontent.com/mwaskom/seaborn-data/master/penguins.csv",
    "https://raw.githubusercontent.com/allisonhorst/palmerpenguins/main/inst/extdata/penguins.csv"
  ],
  "removeDuplicates": true,
  "dedupeFields": [
    "species",
    "island",
    "bill_length_mm",
    "bill_depth_mm",
    "flipper_length_mm",
    "body_mass_g"
  ],
  "keep": "mostComplete",
  "ignoreCase": true,
  "onlyNewItems": false,
  "stateStoreName": "dataset-merge-dedupe-state",
  "joinType": "left",
  "joinMatches": "first",
  "secondPrefix": "second_",
  "includeUnchanged": false,
  "matchColumnNames": true,
  "addSourceField": true,
  "limit": 100,
  "exportFormat": "none",
  "exportFileName": "merged-data",
  "maxFileSizeMb": 200
}
```

# Actor output Schema

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

No description

## `files` (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/mwaskom/seaborn-data/master/penguins.csv",
        "https://raw.githubusercontent.com/allisonhorst/palmerpenguins/main/inst/extdata/penguins.csv"
    ],
    "dedupeFields": [
        "species",
        "island",
        "bill_length_mm",
        "bill_depth_mm",
        "flipper_length_mm",
        "body_mass_g"
    ],
    "keep": "mostComplete",
    "limit": 100
};

// Run the Actor and wait for it to finish
const run = await client.actor("gazidev/dataset-merge-dedupe").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/mwaskom/seaborn-data/master/penguins.csv",
        "https://raw.githubusercontent.com/allisonhorst/palmerpenguins/main/inst/extdata/penguins.csv",
    ],
    "dedupeFields": [
        "species",
        "island",
        "bill_length_mm",
        "bill_depth_mm",
        "flipper_length_mm",
        "body_mass_g",
    ],
    "keep": "mostComplete",
    "limit": 100,
}

# Run the Actor and wait for it to finish
run = client.actor("gazidev/dataset-merge-dedupe").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/mwaskom/seaborn-data/master/penguins.csv",
    "https://raw.githubusercontent.com/allisonhorst/palmerpenguins/main/inst/extdata/penguins.csv"
  ],
  "dedupeFields": [
    "species",
    "island",
    "bill_length_mm",
    "bill_depth_mm",
    "flipper_length_mm",
    "body_mass_g"
  ],
  "keep": "mostComplete",
  "limit": 100
}' |
apify call gazidev/dataset-merge-dedupe --silent --output-dataset

```

## MCP server setup

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

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/mYGY2zXA1KoczwTHk/builds/Jelb5EU34KaT19LMV/openapi.json
