# Merge, Deduplicate & Export Datasets — CSV, Excel, JSON (`tidydata/merge-dedupe-datasets`) Actor

Combine several Apify datasets or CSV/JSON files into one, remove duplicates by any field, filter rows, rename or drop columns, keep only new rows since the last run, and export CSV, Excel or JSON with a download link. Clear errors, no setup.

- **URL**: https://apify.com/tidydata/merge-dedupe-datasets.md
- **Developed by:** [tidydata](https://apify.com/tidydata) (community)
- **Categories:** Developer tools, Automation
- **Stats:** 4 total users, 2 monthly users, 94.8% runs succeeded, 0 bookmarks
- **User rating**: No ratings yet

## Pricing

from $0.20 / 1,000 row in the results

This Actor is paid per event. You are not charged for the Apify platform usage, but only a fixed price for specific events.
Since this Actor supports Apify Store discounts, the price gets lower the higher subscription plan you have.

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, Deduplicate & Export Datasets — CSV, Excel, JSON

Combine **several Apify datasets** (or CSV/JSON files) into one clean dataset: **remove duplicates**, **filter rows**, **rename or drop columns**, keep **only the rows you haven't seen in earlier runs**, and export **CSV, Excel or JSON** with a download link. Built for scheduled scrapers that produce overlapping results.

- ✅ **Pick datasets from a list**: the Apify selector gives this Actor exactly the permission it needs (no API tokens to paste)
- ✅ **Merge** any number of datasets and public CSV/JSON files in one run
- ✅ **Deduplicate by any field(s)** (`url`, `id`, or a combination), keep the first or the last (most recent) row
- ✅ **"Only new rows"**: remembers what earlier runs saw, so each scheduled run outputs just the new items
- ✅ **Filters** in plain text: `price < 50`, `country = ES`, `title contains phone`, `email exists`
- ✅ **Rename / drop columns**, **flatten nested JSON** (`price.value`) so it fits a spreadsheet
- ✅ **CSV (Excel-friendly UTF-8), XLSX and JSON** files with download links; CSV/Excel cells that start with `=`, `+`, `-` or `@` are neutralised so scraped text can't run as a formula
- ✅ **Clear error messages** that tell you what to fix
- ✅ Free **demo** if you run it with an empty input

### How to use it

1. **Datasets to merge**: pick them from your storages (or paste IDs). Optionally add CSV/JSON links.
2. **Remove duplicates by**: type the field(s), e.g. `url`. Choose *first* or *last*.
3. Optional: filters, columns to drop/rename, **Only new rows**, and the file formats you want.
4. Run. The result is in the dataset; files are in the **Output** tab.

#### Run it automatically after another Actor

Add it as an **integration** of your scraper and set *Datasets to merge* to `{{resource.defaultDatasetId}}`. Turn on **Only new rows** and every scheduled run outputs just the new items.

### Filters

One rule per line, all rules must pass. `field operator value`

| Operator | Example |
|---|---|
| `=`, `!=` | `country = ES` |
| `>`, `>=`, `<`, `<=` | `price < 50` (numbers are compared as numbers) |
| `contains`, `not_contains` | `title contains phone` |
| `exists`, `not_exists` | `email exists` |

Filters and duplicate keys use the **original** column names; renaming/dropping happens afterwards.

### Pricing

- **$0.25 per 1,000 rows in the result** ($0.00025 each)
- **$0.005 per file created** (CSV, XLSX or JSON)

Rows removed as duplicates or by filters are **free**. A 100,000-row dataset reduced to 60,000 unique rows costs $15.

### Notes

- Memory for "only new rows" is a named storage in **your** account (default name `merge-dedupe-memory`); use a different name per project, or delete the storage to start over.
- Big merges happen in memory: up to ~2,000,000 rows.
- Only your own data is processed; nothing is sent anywhere else.

# Actor input Schema

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

Pick one or more Apify datasets from your storages (or paste their IDs). They are merged in this order. When this Actor runs as an integration, use {{resource.defaultDatasetId}}.

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

Public links to .csv or .json files (JSON: a list of objects or JSON Lines). Added after the datasets.

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

Rows with the same values in ALL these fields count as duplicates (e.g. url, or id). Nested fields: price.value. Leave empty to keep every row.

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

When several rows are duplicates, keep the first one found or the last one (most recent).

## `onlyNew` (type: `boolean`):

Remember the duplicate keys of every run (needs 'Remove duplicates by' fields) and output only rows that are new. Great for scheduled scrapers.

## `onlyNewMemoryName` (type: `string`):

Runs that share this name share their memory. Use a different name per project.

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

Every rule must pass. Format: field operator value, one per line. Operators: =, !=, >, >=, <, <=, contains, not_contains, exists, not_exists. Examples: price < 50 · country = ES · title contains phone · email exists

## `dropFields` (type: `array`):

Columns to remove from the result. One name per line (nested: price.value).

## `renameFields` (type: `object`):

Old name → new name. Example: {"price.value": "price"}

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

Turn {"price": {"value": 5}} into a column price.value. Needed for CSV/Excel.

## `exportFormats` (type: `array`):

Download links appear in the Output tab. Each file created costs a small fixed fee.

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

Stop after this many rows in the result.

## Actor input object example

```json
{
  "keep": "first",
  "onlyNew": false,
  "onlyNewMemoryName": "merge-dedupe-memory",
  "flatten": true,
  "exportFormats": [
    "csv"
  ],
  "maxRows": 500000
}
```

# Actor output Schema

## `results` (type: `string`):

The merged and cleaned rows.

## `files` (type: `string`):

CSV / Excel / JSON files with public download links.

# 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 = {};

// Run the Actor and wait for it to finish
const run = await client.actor("tidydata/merge-dedupe-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 = {}

# Run the Actor and wait for it to finish
run = client.actor("tidydata/merge-dedupe-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 '{}' |
apify call tidydata/merge-dedupe-datasets --silent --output-dataset

```

## MCP server setup

```json
{
    "mcpServers": {
        "apify": {
            "type": "http",
            "url": "https://mcp.apify.com/?tools=fetch-actor-details,tidydata/merge-dedupe-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/GopabUiu7wAuvdK5X/builds/ZyZbzrQjsXKtNl1J8/openapi.json
