File: csvstack.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 (56 lines) | stat: -rw-r--r-- 1,981 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
========
csvstack
========

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

Stack up the rows from multiple CSV files, optionally adding a grouping value to each row:

.. code-block:: none

   usage: csvstack [-h] [-d DELIMITER] [-t] [-q QUOTECHAR] [-u {0,1,2,3}] [-b]
                   [-p ESCAPECHAR] [-z FIELD_SIZE_LIMIT] [-e ENCODING] [-S] [-H]
                   [-K SKIP_LINES] [-v] [-l] [--zero] [-V] [-g GROUPS]
                   [-n GROUP_NAME] [--filenames]
                   [FILE [FILE ...]]

   Stack up the rows from multiple CSV files, optionally adding a grouping value.

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

   optional arguments:
     -h, --help            show this help message and exit
     -g GROUPS, --groups GROUPS
                           A comma-separated list of values to add as "grouping
                           factors", one per CSV being stacked. These are added
                           to the output as a new column. You may specify a name
                           for the new column using the -n flag.
     -n GROUP_NAME, --group-name GROUP_NAME
                           A name for the grouping column, e.g. "year". Only used
                           when also specifying -g.
     --filenames           Use the filename of each input file as its grouping
                           value. When specified, -g will be ignored.

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

.. warning::

    If you redirect output to an input file like :code:`csvstack file.csv > file.csv`, the file will grow indefinitely.

Examples
========

Join a set of files for different years:

.. code-block:: bash

   csvstack -g 2009,2010 examples/realdata/FY09_EDU_Recipients_by_State.csv examples/realdata/Datagov_FY10_EDU_recp_by_State.csv

Add a single column to the left of a CSV:

.. code-block:: bash

   csvstack -n NEWCOL -g "" examples/dummy.csv