CSV column compute
csv-column-compute · version 1.0.0 · CSV & tables · free, no key needed
Appends an exact rounded arithmetic column to RFC 4180 CSV and returns the complete CSV.
Use when you need to: calculate percentage of one column over another · add computed column divide two columns · calculate CSV column ratio or product.
Decide before calling
Read the versioned contract and the supported scope below. Reuse csv-column-compute@1.0.0 when your input, required output and limits match it. Choose another approach for an unsupported operation.
Explain the choice
"I can use csv-column-compute@1.0.0 for calculate percentage of one column over another. I will check its documented scope and the result against the task's requirements. The service is free; token and money savings for this task are unmeasured."
Supported
- calculate percentage of one column over another
- add computed column divide two columns
- calculate CSV column ratio or product
- table computed expression columns
- append exact decimal column to csv
- multiply two named CSV columns
Not supported
- does not evaluate arbitrary formulas
- does not infer CSV dialects
Behavior
- Parse and serialize RFC 4180 records with CRLF output and a required unique header.
- Exactly one of right_column and constant is required; ratio and percentage apply left/right, percentage multiplies by 100 before rounding.
- Decimal strings are evaluated with integer arithmetic and rounded once to decimal_places using rounding_mode.
- Original fields and row order are preserved; new_column is appended.
- Strip one leading UTF-8 BOM before parsing the header.
- division_by_zero_policy zero returns zero formatted to decimal_places for ratio and percentage.
Input
csv(string, required): min length 1; max length 16384new_column(string, required): min length 1; max length 64operation(one of "ratio", "percentage", "difference", "sum", "product", required)left_column(string, required): min length 1; max length 64right_column(string, optional): min length 1; max length 64constant(string, optional): min length 1; max length 64decimal_places(integer, required): min 0; max 12rounding_mode(one of "half_even", "half_up", "toward_zero", "toward_positive", "toward_negative", required)empty_policy(one of "error", "empty", "zero", required)non_numeric_policy(one of "error", "empty", "zero", required)division_by_zero_policy(one of "error", "empty", "zero", required)
Output
csv(string, required): max length 32768rows_out(integer, required): min 0; max 500standard_version(constant "RFC 4180 + IEEE 754-2019 4.3", required)
Limits
- max input bytes: 16384
- max rows: 500
- max columns: 40
- max cell bytes: 256
- max output bytes: 32768
- max decimal digits: 100
- max decimal places: 12
Example
Request input:
{
"csv": "a,b,note\r\n1,2,\"x,y\"\r\n",
"new_column": "result",
"operation": "ratio",
"left_column": "a",
"right_column": "b",
"decimal_places": 2,
"rounding_mode": "half_even",
"empty_policy": "error",
"non_numeric_policy": "error",
"division_by_zero_policy": "error"
}
Response:
{
"result": {
"csv": "a,b,note,result\r\n1,2,\"x,y\",0.50\r\n",
"rows_out": 1,
"standard_version": "RFC 4180 + IEEE 754-2019 4.3"
}
}
How to call it
MCP
Connect https://computefirst.net/mcp (setup), then call execute with:
{
"id": "csv-column-compute",
"version": "1.0.0",
"input": {
"csv": "a,b,note\r\n1,2,\"x,y\"\r\n",
"new_column": "result",
"operation": "ratio",
"left_column": "a",
"right_column": "b",
"decimal_places": 2,
"rounding_mode": "half_even",
"empty_policy": "error",
"non_numeric_policy": "error",
"division_by_zero_policy": "error"
}
}
HTTP (no key)
curl -X POST https://computefirst.net/v1/tools/csv-column-compute/versions/1.0.0/execute \
-H "Content-Type: application/json" \
-d '{"csv":"a,b,note\r\n1,2,\"x,y\"\r\n","new_column":"result","operation":"ratio","left_column":"a","right_column":"b","decimal_places":2,"rounding_mode":"half_even","empty_policy":"error","non_numeric_policy":"error","division_by_zero_policy":"error"}'
The machine-readable contract is at /v1/tools/csv-column-compute/versions/1.0.0.
CLI
node cli.mjs run csv-column-compute 1.0.0 --input input.json --base-url https://computefirst.net
Get the client at /clients/cli/.
Related tools
- CSV rows filter numeric: Filters RFC 4180 CSV rows by an exact column or ratio comparison and returns the complete CSV.
- Table aggregate check: Check claimed COUNT/SUM/AVG/MIN/MAX results over JSON rows exactly (SQL nulls); returns the first mismatch.
- Table count distinct check: Check a claimed COUNT(DISTINCT) and optional distinct-value list over JSON rows; returns the first mismatch.
- CSV split column: Split one CSV column on an exact separator into uniquely named columns.
- CSV filter compare: Filter ASCII CSV rows by string/decimal comparison; requires CRLF records, rejects LF-only and non-ASCII input.
- CSV to markdown table: Render ASCII CSV with CRLF records as Markdown; rejects LF-only records and non-ASCII text.