Merge & Deduplicate Datasets, CSV & Excel: Remove Duplicates avatar

Merge & Deduplicate Datasets, CSV & Excel: Remove Duplicates

Pricing

from $0.20 / 1,000 rows written

Go to Apify Store
Merge & Deduplicate Datasets, CSV & Excel: Remove Duplicates

Merge & Deduplicate Datasets, CSV & Excel: Remove Duplicates

Merge Apify datasets, CSV, JSON, JSON Lines and Excel files into one clean dataset. Remove duplicates on any fields, ignoring case, spaces and URL variants; keep the first, last or most complete row; filter, pick and rename fields. No code. Pay per row written; duplicates and filtered rows are not.

Pricing

from $0.20 / 1,000 rows written

Rating

0.0

(0)

Developer

WrenTools

WrenTools

Maintained by Community

Actor stats

0

Bookmarked

1

Total users

0

Monthly active users

18 days ago

Last modified

Features

Limited permissions

Share

Merge & Dedup Datasets, CSV, JSON & Excel Files

Combine the results of several scraper runs, lead lists or exports into one clean dataset. Give it your Apify datasets, links to CSV, JSON, JSON Lines or Excel files, or rows pasted as JSON; it merges them, removes the duplicates on the fields you choose, filters, keeps only the fields you want under the names you want, and writes the result to the run's dataset, from which Apify exports CSV, Excel, JSON or XML.

No code to write: every step is an input field. You pay for the rows written; duplicates, filtered rows and failed sources are not charged as written rows. Rows read from Apify datasets you pick cost $0.001 per started 1,000 (see Pricing).

Two lead lists into one: our Python and Node example sends links to two or more files to this Actor, removes the rows whose email is already in the list, keeps the most complete copy of each and saves the result as merged.csv.

See it run: our video Merge Two CSV Files and Remove Duplicates in Python (pandas): Half the People Lost shows a pandas merge that reports no errors and loses half the people, and the questions this Actor's input fields answer; the written version walks through five ways drop_duplicates misses, with the code. We made the video; its narration is a synthetic voice.

Phone numbers typed in different ways: normalise them first with our Phone Number Validator, then deduplicate on its e164 field.

What you get

  • Merge any mix of sources in one run: up to 100 Apify datasets, up to 100 file URLs, and inline rows. Duplicates are found across all of them.
  • Deduplicate on one or more fields (dotted paths such as address.city work), or on whole rows (["*"]):
    • forgiving matching, each switchable: surrounding spaces (on by default), upper and lower case (on by default), runs of spaces, and URL variants (http/https, www., a bare acme.com, trailing slash, #fragment, utm_*, gclid, fbclid and other tracking parameters, query order). 5, "5" and 5.0 are the same value;
    • keep the first, the last, or the most complete duplicate (the one with the most non-empty fields);
    • rows whose dedup fields are all empty are kept, treated as one duplicate group, or dropped: your choice.
  • Filter with 16 operators (equals, contains, starts/ends with, in a list, greater/less than, regular expression, empty/not empty, and their negatives), combined with AND or OR. Numbers are read from text such as "$1,234.50".
  • Shape the output: write only some fields (in your order), drop fields, rename fields, and add a field saying which source each row came from.
  • A SUMMARY for every run: per source, the rows read, filtered out, removed as duplicates and written, and why a source failed.
  • Flat memory on large inputs: rows are streamed and written in batches of 1,000; deduplication keeps only a 16-byte fingerprint per distinct key, not the rows. Datasets are read 5,000 rows at a time, and when you pick output fields only those fields, and the ones your dedup fields and filters use, are downloaded. CSV and JSON Lines files are read from their bytes in pieces.
  • Sized to the run's memory: what a file and the distinct keys need is checked against the run's memory before it is held; what would not fit is refused, or stops the run with the SUMMARY saved (Limits).

Failed sources are reported in the SUMMARY with a reason and write nothing: dataset-not-found, dataset-not-readable, dataset-read-failed, fetch-failed, robots-disallowed, robots-disallowed-redirect (the link redirected to a URL that site's robots.txt does not allow, so it was not fetched there), file-too-large, memory-too-small (the file does not fit the run's memory; the message names the memory that would), unsupported-file, invalid-json, invalid-csv, invalid-xlsx. A file is parsed completely before any of its rows is used, so a damaged file costs nothing. A file whose whole reply takes longer than its time limit is a fetch-failed source whose message starts deadline-exceeded, and the run goes on to the next. The limit is the largest file maxFileSizeMb allows at 333 kB/s, between 60 s and 600 s (150 s at the default 50 MB), and never past the point where the run stops to save its results before its timeout. So a server that sends a file very slowly cannot hold the run.

Respectful by design

  • Your datasets are read only if you pick them. The Actor runs with Apify's limited permissions: it can read exactly the datasets you choose in the input, for reading, and nothing else in your account.
  • Only the files you link are downloaded, one request each. The site's robots.txt is read first and obeyed, and so is the robots.txt of the site any redirect leads to, before the request goes there; downloads from one site are spaced (500 ms by default). No proxy, no browser, no login.
  • Only public internet addresses are fetched: a URL or redirect into a private, loopback or link-local network is refused.
  • Use files and data you have the right to process.

Input

FieldTypeDefaultNotes
datasetIdsdataset[]your Apify datasets (picker)
fileUrlsstring[]links to .csv/.tsv, JSON array, JSON Lines, .xlsx (first sheet) files
itemsarrayrows as JSON objects; other values become {"value": ...}
dedupFieldsstring[]fields that together identify a duplicate; ["*"] = whole row; empty = merge only
keepfirst | last | mostCompletefirstwhich duplicate survives; kept rows stay in reading order
trimValuesbooleantrueignore leading and trailing spaces
ignoreCasebooleantrueignore upper and lower case
collapseWhitespacebooleanfalsetreat runs of spaces, tabs and line breaks as one space
normalizeUrlsbooleanfalsecompare URL values loosely (above)
emptyKeyRowskeep | dedup | dropkeeprows whose dedup fields are all empty
filtersarray[{"field": "country", "op": "in", "value": ["US", "CA"]}, {"field": "score", "op": "gte", "value": 50}]
filterModeall | anyallAND or OR
filtersCaseSensitivebooleanfalse
fieldsstring[]write only these fields, in this order; a missing one is written as null
omitFieldsstring[]top-level fields to leave out
renameFieldsobject{"old name": "new name"}, applied last
addSourceFieldstringadd a field with each row's source (dataset:<id>, the file URL, or items)
maxOutputRowsinteger0stop after this many rows (0 = no limit)
fileFormatauto | csv | json | jsonl | xlsxautodetected from the bytes, file name and content type
csvDelimiterauto | comma | semicolon | tab | pipeautodetected from the header row
maxFileSizeMbinteger501-200
requestDelayMsinteger500pause between downloads from one site

The order of work is: read (datasets, then files, then items, each in input order), filter, deduplicate, then pick, drop and rename. Filters and dedup fields use the original field names. CSV values stay text; text in UTF-8, UTF-16 (with a BOM) and Windows-1252 is read. Excel cells give their saved values, dates as ISO 8601 text.

Output

Each row written is one dataset item, exactly as read (plus your shaping); nothing is wrapped around it. The run's key-value store holds SUMMARY:

{
"rowsRead": 9, "rowsFiltered": 0, "duplicatesRemoved": 3, "emptyKeyRowsDropped": 0,
"rowsWritten": 6, "rowsNotWritten": 0, "distinctKeys": 6, "sourcesRequested": 2, "sourcesFailed": 0,
"truncated": false, "stoppedReason": null, "dedupFields": ["email"], "keep": "mostComplete",
"sources": [
{"source": "https://.../leads-crm.csv", "type": "file", "status": "ok", "format": "csv", "encoding": "utf-8",
"rowsRead": 5, "rowsFiltered": 0, "duplicatesRemoved": 1, "emptyKeyRowsDropped": 0, "rowsWritten": 4,
"rowsNotWritten": 0, "error": null}
]
}

A source's status is ok, failed (nothing read), partial (a dataset whose reading failed part way; the rows before it were used), stopped (the run stopped while reading it) or skipped (the run stopped before it).

Pricing

Pay per event, no start fee:

EventPricePer 1,000
row-written (one row written to the output dataset)$0.0002$0.20
dataset-rows-read (each started 1,000 rows read from Apify datasets you picked, counted over the run)$0.001$0.001 ($1 per million)

Rows filtered out, removed as duplicates, or from a source that failed are not charged as written. Rows read from your Apify datasets carry the small read charge whether or not they are kept, because the platform bills every dataset row read; rows from file URLs and pasted items carry none. Merging 50,000 rows from file URLs into 35,000 unique ones costs $7.00; reading the same 50,000 rows from datasets adds $0.05 (50 blocks of 1,000). When you set a maximum charge for a run, the Actor reads and writes only what it covers and stops; the SUMMARY says "truncated": true and why.

Limits

  • With keep set to last or mostComplete, every source is read before the first row is written (the rows wait in a temporary file on the run's disk), so very large inputs need a longer run timeout. In those modes the run stops reading 90 seconds before its timeout and then writes the kept rows of what it has read: the last or most complete among the rows read, since a source not reached is not seen (it is skipped). Keeping the first, rows are written as they are read. Either way writing stops 30 seconds before the timeout, and the SUMMARY is saved with "truncated": true and "stoppedReason": "the run's timeout was near"; rows read but not written are counted in rowsNotWritten and not charged. A pause between downloads from one site (requestDelayMs) that would end after the point where reading stops is not taken: reading stops there, and that file is skipped.
  • A maximum charge, whichever row is kept. Rows from your datasets are charged as they are read, in pages, before they are written, so the run reads from your datasets only as much as leaves room to write every row it has kept: rows past those its charged blocks of 1,000 already pay for are read only while the charge left after their read charge still pays for writing the rows kept so far and not yet written, and each of them (a row that turns out to be a duplicate frees its room again). Keeping the last or most complete, nothing is written until every source is read; keeping the first, rows are written as they are read. Either way it writes the kept rows of what it has read as far as the charge goes; the SUMMARY says "stoppedReason": "the run's maximum charge was reached".
  • Memory. A file is held in memory while it is read: a CSV or JSON Lines file once, a JSON file with its whole text (once more, or 2 to 4 times for text past Latin-1, such as emoji), an Excel file with what is read of it (its table of shared strings: up to about 18 times its size, so a 40 MB workbook needs the default 1,024 MB). Each distinct key takes up to about 110 bytes when keeping the first, 160 when keeping the last or most complete. At the default 1,024 MB a run reads a 200 MB CSV with 5.7 million distinct keys. The Actor plans for the run's memory less 5% and about 96 MB for itself: a file that would not fit is the source error memory-too-small, which names the memory that would, and the run goes on to the next source; when one more distinct key would not fit, the run stops reading, writes (and charges) the rows it has read, and saves the SUMMARY with "stoppedReason": "the run's memory" and a memoryMessage. Give the run more memory to read further. Datasets are read a page at a time, so only their distinct keys count.
  • Legacy .xls, Google Sheets links and compressed (.gz, .zip) files are not read.
  • Numbers in text are read with , as a thousands separator.

Licences

Python's standard library, the Apify SDK (Apache-2.0), and openpyxl with et-xmlfile (both MIT) for Excel files. No third-party API: nothing leaves the Actor except the downloads you asked for and the reads of the datasets you picked.