LinuxCommandLibrary
GitHubF-DroidGoogle Play Store

csvpy

Interactive Python shell for CSV files

TLDR

Open a CSV file in a Python shell
$ csvpy [data.csv]
copy
Open with tab delimiter
$ csvpy -t [data.tsv]
copy
Load as an agate Table for analysis
$ csvpy --agate [data.csv]
copy
Load as DictReader (rows as dictionaries)
$ csvpy --dict [data.csv]
copy
Open with custom encoding
$ csvpy -e [latin1] [data.csv]
copy
Open file without headers
$ csvpy -H [data.csv]
copy
Open with a custom delimiter
$ csvpy -d "[;]" [data.csv]
copy

SYNOPSIS

csvpy [options] file

DESCRIPTION

csvpy is part of csvkit that loads a CSV file into an interactive Python shell for exploration and analysis. If IPython is installed, it is used as the shell for a richer experience.In default mode, the CSV data is loaded into a variable named reader, a csv.reader object. With --dict, it becomes a DictReader where each row is a dictionary. With --agate, it becomes a table variable with full analysis capabilities including sorting, filtering, and aggregation.This tool is useful for quick data exploration, testing data transformations, and prototyping analysis code. The interactive environment allows immediate feedback while working with the data.

PARAMETERS

FILE

CSV file to load into the Python environment. Also accepts piped input from stdin.
-d CHAR, --delimiter CHAR
Field delimiter character (default: comma).
-t, --tabs
Use tab characters as the field delimiter.
-q CHAR, --quotechar CHAR
Character used for quoting fields.
-e ENCODING, --encoding ENCODING
Specify the input file encoding (e.g., utf-8, latin1).
-H, --no-header-row
Indicate that the file has no header row.
-K N, --skip-lines N
Skip the first N lines of the input before processing.
--agate
Load the file as an agate Table instead of a csv.reader object. The data is available as a variable named table.
--dict
Load as a csv.DictReader where each row is a dictionary keyed by column headers.
-I, --no-inference
Disable type inference when used with --agate, keeping all values as strings.
-S
Disable CSV dialect sniffing.
--blanks
Do not convert empty strings to None.
--null-value VALUES
Convert specified values to None (can specify multiple).
-y N, --sniff-limit N
Limit the number of bytes used for CSV dialect sniffing.
-l, --linenumbers
Insert a column of line numbers at the beginning of the output.
-z N, --field-size-limit N
Maximum length of a single field in the input CSV.
-V, --version
Display version information.

CAVEATS

Large files may use significant memory when loaded entirely. The default csv.reader is consumed after a single iteration; use --agate for reusable data. Requires familiarity with Python for effective use.

HISTORY

csvpy is part of csvkit, created by Christopher Groskopf in 2011. It provides a quick way to drop into Python for ad-hoc data analysis without writing boilerplate file loading code.

SEE ALSO

csvkit(1), csvlook(1), csvstat(1), csvcut(1), csvgrep(1), python(1), ipython(1)

Copied to clipboard
Kai