# Dataset Transformer - Filter, Dedupe, Merge and Join Data (`kotaro-project/dataset-transformer`) Actor

Clean up Apify datasets and JSON or CSV files without code: filter rows, remove duplicates, sort, pick and rename fields, merge sources or join them on a key. Use it after any scraper. Pay per row read, stopping at your spending limit. No API key needed.

- **URL**: https://apify.com/kotaro-project/dataset-transformer.md
- **Developed by:** [KOTARO project](https://apify.com/kotaro-project) (community)
- **Features:** Limited permissions
- **Stats:** 3 total users, 2 monthly users, 100.0% runs succeeded, 0 bookmarks
- **User rating**: No ratings yet

## Pricing

from $0.01 / 1,000 row reads

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

## Dataset Transformer

Clean up data without writing code. Give Apify datasets or JSON and CSV files, and get one tidy dataset back.

### What it does, in this order

1. **Merge or join**: put sources one after another, or join them on a key field with `joinOn`.
2. **Filter**: `equals`, `notEquals`, `contains`, `notContains`, `greaterThan`, `lessThan`, `isEmpty`, `isNotEmpty`, `matches`.
3. **Remove duplicates**: `dedupeBy` keeps the first row for the same values.
4. **Sort**: `sortBy` and `sortDescending`. Rows without a value go last.
5. **Cut**: `limit`.
6. **Pick and rename**: `fields`, then `rename`.

Dotted names reach into nested objects, such as `size.w`. The number of rows after each step is saved in the key-value store as `COUNTS`.

### Example

```json
{
  "datasetIds": ["YOUR_DATASET_ID"],
  "filters": [{"field": "price", "op": "lessThan", "value": 100}],
  "dedupeBy": ["url"],
  "sortBy": "price",
  "fields": ["title", "price", "url"]
}
```

### Pricing

You pay per row read from your sources, not per row in the result, because the work depends on how many rows are read. For example, reading 50,000 rows counts as 50,000 rows even if your filters leave 5.

If you set a maximum spending limit for the run, the Actor reads only as many rows as the limit covers, and a free row with `note` tells you where it stopped. A source that cannot be read gives a row with `error` and is not charged.

### Good to know

- Up to 20 sources and 200,000 rows in one run.
- A file can be JSON, JSON Lines, CSV or TSV, in UTF-8 or Shift_JIS.
- This Actor can read only the datasets you choose in `datasetIds`, with read access. It does not ask for access to the rest of your account. A dataset it cannot open gives an `error` row.
- `joinOn` keeps every row of the first source. If a field exists on both sides, the first source's value is kept.
- CSV values are read as text, so `equals` compares them as text. `greaterThan` and `lessThan` read numbers from text.
- No API key and no other account. Internal addresses are refused.

# Actor input Schema

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

Datasets to read. This Actor gets read access only to the datasets you choose here. Up to 20 sources in total, 200,000 rows in total.

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

Addresses of public JSON, JSON Lines, CSV or TSV files, each up to 50 MB. Internal addresses are refused.

## `joinOn` (type: `string`):

Leave empty to put all sources one after another. With a field name, each row of the first source gets the matching row of the others.

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

Keep only rows that pass all filters. Each one: field, op, value. op is equals, notEquals, contains, notContains, greaterThan, lessThan, isEmpty, isNotEmpty or matches. Example: \[{"field": "price", "op": "lessThan", "value": 100}]

## `dedupeBy` (type: `array`):

Field names. Rows with the same values in these fields are kept once, the first one.

## `sortBy` (type: `string`):

Field to sort by. Numbers sort as numbers. Rows without a value go last.

## `sortDescending` (type: `boolean`):

Sort from largest to smallest.

## `fields` (type: `array`):

Field names to keep. Dotted names reach into nested objects, such as size.w. Leave empty to keep all.

## `rename` (type: `object`):

Old name to new name. Example: {"title": "name"}

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

Cut the result to this many rows. This does not lower the charge, which is per row read.

## Actor input object example

```json
{
  "fileUrls": [
    "https://raw.githubusercontent.com/datasets/country-list/main/data.csv"
  ],
  "filters": [
    {
      "field": "Name",
      "op": "contains",
      "value": "land"
    }
  ],
  "sortDescending": false,
  "limit": 10
}
```

# Actor output Schema

## `results` (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"
    ],
    "filters": [
        {
            "field": "Name",
            "op": "contains",
            "value": "land"
        }
    ],
    "limit": 10
};

// Run the Actor and wait for it to finish
const run = await client.actor("kotaro-project/dataset-transformer").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"],
    "filters": [{
            "field": "Name",
            "op": "contains",
            "value": "land",
        }],
    "limit": 10,
}

# Run the Actor and wait for it to finish
run = client.actor("kotaro-project/dataset-transformer").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"
  ],
  "filters": [
    {
      "field": "Name",
      "op": "contains",
      "value": "land"
    }
  ],
  "limit": 10
}' |
apify call kotaro-project/dataset-transformer --silent --output-dataset

```

## MCP server setup

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

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/IeiPMFhCnVRwIaMeS/builds/QKqrNeZzXdrlpMcl5/openapi.json
