# Merge Datasets: Combine Datasets, Align Columns (`ucchiii/merge-datasets`) Actor

Returns one dataset with the same columns in every row, merged from several Apify datasets plus CSV or JSON files by URL. Rename columns to line them up, keep all or only shared columns, and add a source column. Empty input runs a free demo.

- **URL**: https://apify.com/ucchiii/merge-datasets.md
- **Developed by:** [Actor Factory](https://apify.com/ucchiii) (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.21 / 1,000 merged rows

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

**Returns one dataset with the same columns in every row, merged from several Apify runs (and CSV or JSON files).**

- **Cost:** $0.30 per 1,000 merged rows. **The $5 monthly free credit covers about 16,000 rows.**
- **Output example:** see *What you get* below — two shops with different columns, one aligned table.

Pick the datasets of your scraper runs, optionally add links to CSV, TSV, JSON or NDJSON files, press **Start**: every row of every source lands in one dataset, in order, with one shared set of columns. A column one source lacks is filled with `null`, so the CSV or Excel export lines up. Rename columns that are called differently in different sources (`Title` → `name`), keep only the columns every source shares, and add a `_source` column that says where each row came from.

**Try it free:** leave datasets and files empty and press **Start** — two built-in sample shop lists with different columns are merged (not charged, rows carry `_demo: true`).

### What you get

Two sources with different columns, merged with `renameColumns: {"Title": "name"}` and the source column on:

| name | price | url | inStock | rating | \_source |
|---|---|---|---|---|---|
| Ceramic Mug | 12.5 | https://shop-a.example/mug | true | null | demo-shop-a |
| Teak Spoon | 6.9 | https://shop-a.example/spoon | true | null | demo-shop-a |
| Glass Teapot | 31 | https://shop-b.example/teapot | null | 4.7 | demo-shop-b |

- **Every row is kept.** Nothing is de-duplicated: the same row in two sources appears twice. To remove duplicates, use Dataset Merge & Dedup from the same developer.
- **Values stay as they are.** Numbers, booleans, nested objects and arrays from datasets are copied unchanged; CSV values stay text exactly as in the file (`00123` stays `00123`).
- **Big inputs are fine.** Rows are streamed, so a million rows merge within the default memory.

### How to use

1. **Datasets**: pick or paste the datasets to merge (dataset IDs or Apify Console URLs). They are read in the order given.
2. Optional **CSV / JSON file URLs**: public links, merged after the datasets.
3. Optional: **Columns** (`all` or `common`), **Rename columns**, **Add a source column**.

```json
{
  "datasetIds": ["WkzbQMuFYuamGv3YF", "3nQ8cL2xTbYk9VdR1"],
  "fileUrls": ["https://example.com/leads-march.csv"],
  "columns": "all",
  "renameColumns": {"Company Name": "company", "E-mail": "email"},
  "addSourceColumn": true
}
```

### Output

- **Dataset**: the merged rows. Columns are listed in the order they first appear across sources (`_source` last). Download as CSV, Excel, JSON, XML or HTML from the run page.
- **STATS** record: rows per source, the output columns, renamed columns, rows written and charged, and whether the run stopped early.

| field | meaning |
|---|---|
| *your columns* | the union (or the shared set) of the source columns; `null` where a source has no value |
| `_source` | dataset ID or file URL of the row (only with **Add a source column**) |
| `_extra` | extra cells of a CSV line that is longer than its header |

### Limits (cannot be raised by input)

- Up to 10 sources per run (datasets and files together) and 1,000,000 output rows per run
- Files up to 100 MB each; JSON arrays up to 50 MB (an array has to be read whole — use NDJSON for bigger files); up to 2,000 different columns
- Excel files are not read — save them as CSV first. Public files only (no login); links to internal network addresses are blocked
- A source that cannot be read (wrong dataset ID, HTTP error, broken JSON) stops the run **before anything is written or charged**
- Set a maximum cost per run to cap spend: the run stops cleanly at that number of rows (status Succeeded), keeps what was merged and says so in the status message and STATS

### Pricing

Pay per event: **$0.0003 per merged row** written to the output dataset ($0.30 per 1,000 rows). Failed runs and the demo are free.
Store discounts apply automatically: BRONZE −10%, SILVER −20%, GOLD −30%.
On the Apify Free plan, the $5 of monthly platform credit covers about 16,000 rows a month.

### FAQ

**Does it remove duplicates?** No, by design. Every row of every source is kept. Use Dataset Merge & Dedup if you need duplicates removed by `url`, `email` or other fields.

**My sources call the same column differently.** Use **Rename columns**: `{"Title": "name"}` puts the values of `Title` into `name`. If a row has both, the first non-empty value wins.

**Can I keep only the columns all sources have?** Yes: set **Columns** to `common`. The STATS record notes how many columns were left out.

**Is the order kept?** Yes: sources in the order given (datasets first, then files), rows in their original order.

**Does it work with datasets from other Actors' runs?** Yes, any dataset your account can read. Paste the `defaultDatasetId` of a run, or the dataset URL from Apify Console.

### More tools from the same developer

- [Dataset Transform Pro](https://apify.com/ucchiii/dataset-transform-pro) — merge Apify datasets and CSV / JSON / Excel / Google Sheets files, then filter, rename, dedupe (exact or fuzzy), explode arrays and keep only rows new since the last run, export CSV / XLSX / JSON
- [Remove Duplicates](https://apify.com/ucchiii/dataset-dedup-merge) — merge Apify datasets and remove duplicates by the fields you choose
- [Filter CSV, JSON or Dataset Rows by Condition](https://apify.com/ucchiii/filter-rows) — keep only the rows of a CSV, JSON file or dataset that match simple conditions like country = US or price > 100
- [CSV to Excel Converter](https://apify.com/ucchiii/csv-xlsx-converter) — convert CSV, TSV, Excel XLSX, JSON and NDJSON files or Apify datasets into each other
- [Dataset Splitter](https://apify.com/ucchiii/dataset-splitter) — split a dataset or CSV/JSON file into parts by rows, parts, column value or size, or take a random sample

# Actor input Schema

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

Apify datasets to merge, in order (for example the defaultDatasetId of finished scraper runs). You can paste dataset URLs from Apify Console too. Up to 10 sources per run (datasets and files together). Leave datasets and files empty for a free demo.

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

Optional public http(s) links to CSV, TSV, JSON or NDJSON files, merged after the datasets. Each file up to 100 MB (JSON arrays up to 50 MB; NDJSON has no extra limit).

## `columns` (type: `string`):

Default 'all': every column of every source, in the order they first appear. 'common': only the columns every source has.

## `renameColumns` (type: `object`):

Optional. Line up columns that have different names in different sources, as {"old name": "new name"}, for example {"Title": "name", "E-mail": "email"}. Applied before the columns are aligned.

## `addSourceColumn` (type: `boolean`):

Add a '\_source' column with the dataset ID or file URL each row came from.

## Actor input object example

```json
{
  "fileUrls": [
    "https://raw.githubusercontent.com/mwaskom/seaborn-data/master/attention.csv",
    "https://raw.githubusercontent.com/mwaskom/seaborn-data/master/anagrams.csv"
  ],
  "columns": "all",
  "addSourceColumn": false
}
```

# Actor output Schema

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

Every row of every source, with the same columns in the same order (missing values are null). Download as CSV, JSON or Excel.

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

Record STATS: rows per source, output columns, renamed columns, rows written and charged, and whether the run stopped early.

# 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/attention.csv",
        "https://raw.githubusercontent.com/mwaskom/seaborn-data/master/anagrams.csv"
    ]
};

// Run the Actor and wait for it to finish
const run = await client.actor("ucchiii/merge-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/mwaskom/seaborn-data/master/attention.csv",
        "https://raw.githubusercontent.com/mwaskom/seaborn-data/master/anagrams.csv",
    ] }

# Run the Actor and wait for it to finish
run = client.actor("ucchiii/merge-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/mwaskom/seaborn-data/master/attention.csv",
    "https://raw.githubusercontent.com/mwaskom/seaborn-data/master/anagrams.csv"
  ]
}' |
apify call ucchiii/merge-datasets --silent --output-dataset

```

## MCP server setup

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