Combines multiple CSV files into a single one by printing to standard out. A new column, "filename", is added to the combined CSV to signify the origin file of a row of data.
There are two primary ways to provide the CSV files that will be combined.
Place all of your CSV files into a single directory and pass it as an argument to csvcombine.py
python csvcombine.py ./fixtures/
The paths to the files can be listed as multiple arguments
python csvcombine.py ./fixtures/accessories.csv ./fixtures/clothing.csv ./fixtures/household_cleaners.csv
Note: The methods cannot be combined. You must either include a single directory containing the relevant CSV files or each individual file path.
To save the newly combined CSV file, one should redirect the output standard output to a file. For example,
python csvcombine.py ./fixtures/accessories.csv ./fixtures/clothing.csv ./fixtures/household_cleaners.csv > combined_output.csv
If we have two files, appliances.csv and furniutre.csv:
email_address | item | cost |
---|---|---|
[email protected] | blender | $500 |
[email protected] | microwave | $1000 |
item | color |
---|---|
chair | green |
desk | brown |
sofa | tan |
then csvcombine will output
email_address | item | cost | color | filename |
---|---|---|---|---|
[email protected] | blender | $500 | appliances.csv | |
[email protected] | microwave | $1000 | appliances.csv | |
chair | green | furniture.csv | ||
desk | brown | furniture.csv | ||
sofa | tan | furniture.csv |
- pytest
- pytest-mock