# CSV group count

`csv-group-count` · version 1.0.0 · CSV & tables · free, no key needed

Count CSV rows by exact named-column tuples in first-seen order.

**Use when you need to: csv group count · count csv rows by columns · csv group by.**

## Supported

- csv group count
- count csv rows by columns
- csv group by

## Not supported

- sum other columns
- sort groups
- case fold
- numeric bins

## Behavior

- The first CSV record is the header row.
- Duplicate and empty header names are rejected.
- group_columns is a non-empty unique list of exact header names.
- A group key is the JSON array of exact cell strings for those columns.
- No trimming, case folding, type coercion, or other normalization is performed.
- Groups appear in first-seen order.
- Output CSV headers are the group_columns followed by count.
- count is a base-10 integer string of the matching data-row count.
- A group column named count is rejected as a header collision.
- An empty document is invalid when group_columns is supplied.
- A header-only document yields the group headers plus count and zero data rows.

## Input

- `csv` (string, required): max length 256000
- `group_columns` (array of string, required): min items 1; max items 32; each min length 1

## Output

- `csv` (string, required)
- `rows_in` (integer, required)
- `groups_out` (integer, required)

## Limits

- max input bytes: 256000
- max data rows: 5000
- max columns: 256
- max header name bytes: 256
- max group columns: 32

## Example

Request input:

```json
{
  "csv": "k,v\na,1\na,2\nb,1\n",
  "group_columns": [
    "k"
  ]
}
```

Response:

```json
{
  "result": {
    "csv": "k,count\na,2\nb,1\n",
    "rows_in": 3,
    "groups_out": 2
  }
}
```

## How to call it

### MCP

Connect `https://computefirst.net/mcp` ([setup](/docs#connect)), then call `execute` with:

```json
{
  "id": "csv-group-count",
  "version": "1.0.0",
  "input": {
    "csv": "k,v\na,1\na,2\nb,1\n",
    "group_columns": [
      "k"
    ]
  }
}
```

### HTTP (no key)

```sh
curl -X POST https://computefirst.net/v1/tools/csv-group-count/versions/1.0.0/execute \
  -H "Content-Type: application/json" \
  -d '{"csv":"k,v\na,1\na,2\nb,1\n","group_columns":["k"]}'
```

The machine-readable contract is at [/v1/tools/csv-group-count/versions/1.0.0](/v1/tools/csv-group-count/versions/1.0.0).

### CLI

```sh
node cli.mjs run csv-group-count 1.0.0 --input input.json --base-url https://computefirst.net
```

Get the client at [/clients/cli/](/clients/cli/).

## Related tools

- [CSV dedupe](/tools/csv-dedupe): Remove duplicate CSV data rows while preserving the first occurrence.
- [CSV sort](/tools/csv-sort): Stably sort CSV rows by exact named string columns.
- [CSV row diff](/tools/csv-row-diff): Compare two CSV documents with identical headers by unique key tuples and report added, removed, and changed rows.
- [CSV split column](/tools/csv-split-column): Split one CSV column on an exact separator into uniquely named columns.
- [CSV transpose](/tools/csv-transpose): Transpose a CSV matrix including the header row, then re-validate headers.
- [CSV add row number](/tools/csv-add-row-number): Prepend a 1-based row_number column of canonical integer strings.
