| 1 |
======= |
| 2 |
csvstat |
| 3 |
======= |
| 4 |
|
| 5 |
Description |
| 6 |
=========== |
| 7 |
|
| 8 |
Prints descriptive statistics for all columns in a CSV file. Will intelligently determine the type of each column and then print analysis relevant to that type (ranges for dates, mean and median for integers, etc.): |
| 9 |
|
| 10 |
.. code-block:: bash |
| 11 |
|
| 12 |
usage: csvstat [-h] [-d DELIMITER] [-t] [-q QUOTECHAR] [-u {0,1,2,3}] [-b] |
| 13 |
[-p ESCAPECHAR] [-z FIELD_SIZE_LIMIT] [-e ENCODING] [-L LOCALE] |
| 14 |
[-S] [--blanks] [--null-value NULL_VALUES [NULL_VALUES ...]] |
| 15 |
[--date-format DATE_FORMAT] [--datetime-format DATETIME_FORMAT] |
| 16 |
[-H] [-K SKIP_LINES] [-v] [-l] [--zero] [-V] [--csv] [--json] |
| 17 |
[-i INDENT] [-n] [-c COLUMNS] [--type] [--nulls] [--non-nulls] |
| 18 |
[--unique] [--min] [--max] [--sum] [--mean] [--median] |
| 19 |
[--stdev] [--len] [--max-precision] [--freq] |
| 20 |
[--freq-count FREQ_COUNT] [--count] |
| 21 |
[--decimal-format DECIMAL_FORMAT] [-G] [-y SNIFF_LIMIT] [-I] |
| 22 |
[FILE] |
| 23 |
|
| 24 |
Print descriptive statistics for each column in a CSV file. |
| 25 |
|
| 26 |
positional arguments: |
| 27 |
FILE The CSV file to operate on. If omitted, will accept |
| 28 |
input as piped data via STDIN. |
| 29 |
|
| 30 |
optional arguments: |
| 31 |
-h, --help show this help message and exit |
| 32 |
--csv Output results as a CSV table, rather than plain text. |
| 33 |
--json Output results as JSON text, rather than plain text. |
| 34 |
-i INDENT, --indent INDENT |
| 35 |
Indent the output JSON this many spaces. Disabled by |
| 36 |
default. |
| 37 |
-n, --names Display column names and indices from the input CSV |
| 38 |
and exit. |
| 39 |
-c COLUMNS, --columns COLUMNS |
| 40 |
A comma-separated list of column indices, names or |
| 41 |
ranges to be examined, e.g. "1,id,3-5". Defaults to |
| 42 |
all columns. |
| 43 |
--type Only output data type. |
| 44 |
--nulls Only output whether columns contains nulls. |
| 45 |
--non-nulls Only output counts of non-null values. |
| 46 |
--unique Only output counts of unique values. |
| 47 |
--min Only output smallest values. |
| 48 |
--max Only output largest values. |
| 49 |
--sum Only output sums. |
| 50 |
--mean Only output means. |
| 51 |
--median Only output medians. |
| 52 |
--stdev Only output standard deviations. |
| 53 |
--len Only output the length of the longest values. |
| 54 |
--max-precision Only output the most decimal places. |
| 55 |
--freq Only output lists of frequent values. |
| 56 |
--freq-count FREQ_COUNT |
| 57 |
The maximum number of frequent values to display. |
| 58 |
--count Only output total row count. |
| 59 |
--decimal-format DECIMAL_FORMAT |
| 60 |
%-format specification for printing decimal numbers. |
| 61 |
Defaults to locale-specific formatting with "%.3f". |
| 62 |
-G, --no-grouping-separator |
| 63 |
Do not use grouping separators in decimal numbers. |
| 64 |
-y SNIFF_LIMIT, --snifflimit SNIFF_LIMIT |
| 65 |
Limit CSV dialect sniffing to the specified number of |
| 66 |
bytes. Specify "0" to disable sniffing entirely, or |
| 67 |
"-1" to sniff the entire file. |
| 68 |
-I, --no-inference Disable type inference (and --locale, --date-format, |
| 69 |
--datetime-format, --no-leading-zeroes) when parsing |
| 70 |
the input. |
| 71 |
|
| 72 |
See also: :doc:`../common_arguments`. |
| 73 |
|
| 74 |
Examples |
| 75 |
======== |
| 76 |
|
| 77 |
Basic use: |
| 78 |
|
| 79 |
.. code-block:: bash |
| 80 |
|
| 81 |
csvstat examples/realdata/FY09_EDU_Recipients_by_State.csv |
| 82 |
|
| 83 |
When an statistic name is passed, only that stat will be printed: |
| 84 |
|
| 85 |
.. code-block:: console |
| 86 |
|
| 87 |
$ csvstat --min examples/realdata/FY09_EDU_Recipients_by_State.csv |
| 88 |
1. State Name: None |
| 89 |
2. State Abbreviate: None |
| 90 |
3. Code: 1 |
| 91 |
4. Montgomery GI Bill-Active Duty: 435 |
| 92 |
5. Montgomery GI Bill- Selective Reserve: 48 |
| 93 |
6. Dependents' Educational Assistance: 118 |
| 94 |
7. Reserve Educational Assistance Program: 60 |
| 95 |
8. Post-Vietnam Era Veteran's Educational Assistance Program: 1 |
| 96 |
9. TOTAL: 768 |
| 97 |
10. j: None |
| 98 |
|
| 99 |
If a single stat *and* a single column are requested, only a value will be returned: |
| 100 |
|
| 101 |
.. code-block:: console |
| 102 |
|
| 103 |
$ csvstat -c 4 --mean examples/realdata/FY09_EDU_Recipients_by_State.csv |
| 104 |
6,263.904 |