File: csvlook.rst

package info (click to toggle)
csvkit 2.2.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 40,664 kB
  • sloc: python: 4,924; perl: 1,000; makefile: 131; sql: 4
file content (90 lines) | stat: -rw-r--r-- 3,731 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
=======
csvlook
=======

Description
===========

Renders a CSV to the command line in a Markdown-compatible, fixed-width format:

.. code-block:: none

   usage: csvlook [-h] [-d DELIMITER] [-t] [-q QUOTECHAR] [-u {0,1,2,3}] [-b]
                  [-p ESCAPECHAR] [-z FIELD_SIZE_LIMIT] [-e ENCODING] [-L LOCALE]
                  [-S] [--blanks] [--null-value NULL_VALUES [NULL_VALUES ...]]
                  [--date-format DATE_FORMAT] [--datetime-format DATETIME_FORMAT]
                  [-H] [-K SKIP_LINES] [-v] [-l] [--zero] [-V]
                  [--max-rows MAX_ROWS] [--max-columns MAX_COLUMNS]
                  [--max-column-width MAX_COLUMN_WIDTH]
                  [--max-precision MAX_PRECISION] [--no-number-ellipsis]
                  [-y SNIFF_LIMIT] [-I]
                  [FILE]

   Render a CSV file in the console as a Markdown-compatible, fixed-width table.

   positional arguments:
     FILE                  The CSV file to operate on. If omitted, will accept
                           input as piped data via STDIN.

   optional arguments:
     -h, --help            show this help message and exit
     --max-rows MAX_ROWS   The maximum number of rows to display before
                           truncating the data.
     --max-columns MAX_COLUMNS
                           The maximum number of columns to display before
                           truncating the data.
     --max-column-width MAX_COLUMN_WIDTH
                           Truncate all columns to at most this width. The
                           remainder will be replaced with ellipsis.
     --max-precision MAX_PRECISION
                           The maximum number of decimal places to display. The
                           remainder will be replaced with ellipsis.
     --no-number-ellipsis  Disable the ellipsis if --max-precision is exceeded.
     -y SNIFF_LIMIT, --snifflimit SNIFF_LIMIT
                           Limit CSV dialect sniffing to the specified number of
                           bytes. Specify "0" to disable sniffing entirely, or
                           "-1" to sniff the entire file.
     -I, --no-inference    Disable type inference (and --locale, --date-format,
                           --datetime-format, --no-leading-zeroes) when parsing
                           the input.

If a table is too wide to display properly try piping the output to ``less -S`` or truncating it using :doc:`csvcut`.

If the table is too long, try filtering it down with grep or piping the output to ``less``.

See also: :doc:`../common_arguments`.

.. note::

   The fractional part of a decimal numberal is always truncated. To control this truncation, use ``--no-inference`` along with ``--max-column-width``.

Examples
========

Basic use:

.. code-block:: bash

   csvlook examples/testfixed_converted.csv

This tool is especially useful as a final operation when piping through other tools:

.. code-block:: bash

   csvcut -c 9,1 examples/realdata/FY09_EDU_Recipients_by_State.csv | csvlook

If a data row contains more cells than the header row, csvlook will error. Use :doc:`csvclean` to remove such rows.

To ignore the extra cells, instead:

.. code-block:: bash

   csvcut -C "" examples/bad.csv | csvlook

If these rows are at the top of the file (for example, copyright notices), you can skip the rows:

.. code-block:: bash

   csvlook --skip-lines 1 examples/bad.csv

This error can also occur if csvlook incorrectly deduces ("sniffs") the CSV format. To disable CSV sniffing, set :code:`--snifflimit 0` and then, if necessary, set the :code:`--delimiter` and :code:`--quotechar` options yourself. Or, set :code:`--snifflimit -1` to use the entire file as the sample, instead of the first 1024 bytes.