| 1 |
======== |
| 2 |
csvstack |
| 3 |
======== |
| 4 |
|
| 5 |
Description |
| 6 |
=========== |
| 7 |
|
| 8 |
Stack up the rows from multiple CSV files, optionally adding a grouping value to each row: |
| 9 |
|
| 10 |
.. code-block:: none |
| 11 |
|
| 12 |
usage: csvstack [-h] [-d DELIMITER] [-t] [-q QUOTECHAR] [-u {0,1,2,3}] [-b] |
| 13 |
[-p ESCAPECHAR] [-z FIELD_SIZE_LIMIT] [-e ENCODING] [-S] [-H] |
| 14 |
[-K SKIP_LINES] [-v] [-l] [--zero] [-V] [-g GROUPS] |
| 15 |
[-n GROUP_NAME] [--filenames] |
| 16 |
[FILE [FILE ...]] |
| 17 |
|
| 18 |
Stack up the rows from multiple CSV files, optionally adding a grouping value. |
| 19 |
|
| 20 |
positional arguments: |
| 21 |
FILE The CSV file(s) to operate on. If omitted, will accept |
| 22 |
input as piped data via STDIN. |
| 23 |
|
| 24 |
optional arguments: |
| 25 |
-h, --help show this help message and exit |
| 26 |
-g GROUPS, --groups GROUPS |
| 27 |
A comma-separated list of values to add as "grouping |
| 28 |
factors", one per CSV being stacked. These are added |
| 29 |
to the output as a new column. You may specify a name |
| 30 |
for the new column using the -n flag. |
| 31 |
-n GROUP_NAME, --group-name GROUP_NAME |
| 32 |
A name for the grouping column, e.g. "year". Only used |
| 33 |
when also specifying -g. |
| 34 |
--filenames Use the filename of each input file as its grouping |
| 35 |
value. When specified, -g will be ignored. |
| 36 |
|
| 37 |
See also: :doc:`../common_arguments`. |
| 38 |
|
| 39 |
.. warning:: |
| 40 |
|
| 41 |
If you redirect output to an input file like :code:`csvstack file.csv > file.csv`, the file will grow indefinitely. |
| 42 |
|
| 43 |
Examples |
| 44 |
======== |
| 45 |
|
| 46 |
Join a set of files for different years: |
| 47 |
|
| 48 |
.. code-block:: bash |
| 49 |
|
| 50 |
csvstack -g 2009,2010 examples/realdata/FY09_EDU_Recipients_by_State.csv examples/realdata/Datagov_FY10_EDU_recp_by_State.csv |
| 51 |
|
| 52 |
Add a single column to the left of a CSV: |
| 53 |
|
| 54 |
.. code-block:: bash |
| 55 |
|
| 56 |
csvstack -n NEWCOL -g "" examples/dummy.csv |