Skip to main content

Coming from csvkit

undatum covers the csvkit workflow (cut, grep, sort, join, stack, statistics, conversion and SQL), and runs it on JSON Lines, Parquet, Excel, XML and the other formats it reads, not only CSV. This page maps csvkit 2.x commands to undatum.

What works differently​

  • Columns by name. Columns are chosen by name with --fields; csvkit's -c also takes column numbers.
  • Values stay text. undatum reads CSV values as text, as they are in the file; csvkit guesses types with agate. Sort numbers with --numeric, and compare numbers in --where, which types text automatically.
  • Output format. Records go to stdout in the input's format, or to --output in the format of its extension (--format-out overrides it). csvkit always writes CSV.
  • Two engines. Commands with --engine run in DuckDB when it reads the input, and in Python otherwise, with the same results.
  • JSON results. count, headers, stats, schema, validate and the other informational commands print a versioned JSON document with --json.

Command map​

csvkitundatumNotes
csvcut -c name,cityundatum select --fields name,cityNames, in the order given
csvcut -C emailundatum select --fields ...List the fields to keep
csvcut -nundatum headers
csvgrep -c city -m Berlinundatum search --fields city --pattern Berlin--pattern is a regular expression
csvgrep -c city -r '^B'undatum search --fields city --pattern '^B'--ignore-case for case-insensitive matches
csvgrep -iundatum select --where "city <> 'Berlin'"Any DuckDB SQL condition
csvsort -c amount -rundatum sort --by amount --numeric amount --descText order unless the field is in --numeric
csvjoin -c id a.csv b.csvundatum join a.csv b.csv --on idTwo files; the key has the same name in both
csvjoin --left / --right / --outerundatum join --type left / right / full
csvstack a.csv b.csvundatum cat a.csv b.csv--mode columns puts the files side by side
csvlookundatum tableThe first 20 rows; -n for more
csvstatundatum stats--json for a undatum.stats/1 document
csvstat --freq -c cityundatum frequency --fields city
csvstat --countundatum count--where counts the matching records
csvjson data.csvundatum convert data.csv data.json
csvjson --streamundatum convert data.csv data.jsonl
in2csv workbook.xlsx --sheet Citiesundatum convert workbook.xlsx cities.csv --table Citiesxls, xlsx, xlsm, xlsb and ods, with typed values
in2csv -n workbook.xlsxundatum formats tables workbook.xlsx
in2csv data.jsonundatum convert data.json data.csvAlso GeoJSON, DBF, fixed width and the other readable formats
csvformat -D ';'undatum fmt --delimiter ';'--quote, --escape, --line-ending
csvformat -Tundatum convert data.csv data.tsv
csvcleanundatum fixlengthsPads short rows or truncates long ones (--strategy)
csvsql --query "..." data.csvundatum sql "..." data.csvDuckDB SQL; the table is data, or the file name without its extension
csvsql --db URL --insert data.csvundatum db load data.csv --db URL --table NAME --create-tablePostgreSQL, MySQL, SQL Server, ClickHouse, SQLite, DuckDB, MongoDB, Elasticsearch
sql2csv --db URL --query "..."undatum db query "..." --db URL
csvpy data.csvDataset.read("data.csv")The Python SDK
noneundatum head, undatum tail, undatum sliceFirst, last or a range of records

Side by side​

# csvcut -c name,city data.csv
undatum select data.csv --fields name,city

# csvgrep -c city -m Berlin data.csv
undatum search data.csv --fields city --pattern Berlin

# csvgrep -c amount ... cannot compare numbers; --where can
undatum select data.csv --where "amount > 100 AND city = 'Berlin'"

# csvsort -c amount -r data.csv
undatum sort data.csv --by amount --numeric amount --desc

# csvjoin -c id --left people.csv orders.csv
undatum join people.csv orders.csv --on id --type left

# csvstack people.csv orders.csv
undatum cat people.csv orders.csv

# csvlook data.csv
undatum table data.csv --fields name,city

# csvstat data.csv
undatum stats data.csv

# csvjson data.csv > data.json
undatum convert data.csv data.json

# in2csv --sheet Cities workbook.xlsx > cities.csv
undatum convert workbook.xlsx cities.csv --table Cities

# csvsql --query "SELECT city, COUNT(*) AS n FROM data GROUP BY city" data.csv
undatum sql "SELECT city, COUNT(*) AS n FROM data GROUP BY city" data.csv

The same commands read other formats as they are:

undatum select data.parquet --fields name,city
undatum search data.jsonl --fields city --pattern Berlin
undatum stats data.jsonl.gz

What undatum adds​

See also Coming from qsv and the cheat sheet.