CSVSTACK(1)

πŸ‘‘ CSVSTACK(1) πŸ‘‘

okay bestie, welcome to csvstack, which is part of csvkit (fr fr the whole family of tools is iconic). This page is literally just csvstack Documentation, and it's about to change your whole spreadsheet-adjacent life. πŸ¦‹


✨ NAME ✨

csvstack β€” csvstack Documentation. that's it, that's the name. short. sweet. slays. πŸ’…


🌸 DESCRIPTION 🌸

so what does she DO? she stacks up the rows from multiple CSV files, and if you want, she can also add a grouping value to each row so you know which file each row came from. lowkey genius. 🧚

here's the whole usage thing, verbatim, because I would never edit her:

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.

and now the vibes-based tour of every single one of those, because I'm not skipping a thing:

πŸŽ€ positional arguments πŸŽ€

  • FILE β€” the CSV file(s) you want to operate on. you can pass more than one, like [FILE [FILE ...]]. and if you just... don't? she'll accept input as piped data via STDIN instead. queen of flexibility. 🫢

πŸ’– optional arguments πŸ’–

  • -h, --help β€” show this help message and exit. the classic. the icon. use it when you're lost.
  • -g GROUPS, --groups GROUPS β€” a comma-separated list of values to add as "grouping factors", one per CSV being stacked. these get added to the output as a new column. and you can name that new column with the -n flag if you want to be fancy about it. πŸ’…
  • -n GROUP_NAME, --group-name GROUP_NAME β€” a name for the grouping column, like "year". heads up though: this is only used when you also specify -g. no -g, no name, no column. periodt.
  • --filenames β€” use the filename of each input file as its grouping value. and when you do this, -g will be ignored. I don't make the rules, I just report them. πŸ™ˆ
✨ SEE ALSO: Arguments common to all tools. (iykyk β€” that's where the shared flags live.)
🚨 WARNING, and I need you to READ this one: if you redirect output to an input file like csvstack file.csv > file.csv, the file will grow indefinitely. not a little. indefinitely. that's not a vibe, that's a cursed loop. don't do it bestie 😭

πŸ¦‹ EXAMPLES πŸ¦‹

joining a set of files for different years

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

two years, two files, one stack, one grouping column. ate. πŸ”₯

adding a single column to the left of a CSV

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

a whole new column on the left, name and all. iconic. πŸ‘‘


πŸ’œ AUTHOR πŸ’œ

Christopher Groskopf and contributors. we love a collaborator moment. 🫢


2016, Christopher Groskopf and James McKinney. yes ma'am, documented and protected. ✨


and that's the whole page, babe β€” this was csvkit version 2.2.0, dated Aug 16, 2024. go stack something beautiful. πŸ“πŸ’–πŸŒΈ

πŸ“¦ where this page comes from