This Python script compares two CSV files and generates a new CSV file containing the differences between them. The script is compatible with Python 2.7.
- Python 2.7
-
Save the script as
compare_csvs.py
. -
Open a terminal (or Command Prompt on Windows) and navigate to the directory where you saved the script.
-
Run the script with the following command:
python compare_csvs.py <file1_path> <file2_path> [-o <output_file_path>]
Replace <file1_path>
and <file2_path>
with the paths to your input CSV files. Optionally, provide the -o
flag followed by <output_file_path>
to specify a custom output file path. If the -o
flag is not provided, the default output file name will be "differences.csv" in the current working directory.
Suppose you have two CSV files named data_old.csv
and data_new.csv
, and you want to find the differences between them and save the result as differences.csv
. Run the following command:
python compare_csvs.py data_old.csv data_new.csv -o differences.csv
This command will compare the two input files and generate a new file named differences.csv
containing the differences.
To run the tests, execute the following command in your terminal:
python -m unittest test_compare_csvs