csv compare
v1.0.3
CSVComparetool允许您根据指定的列标识符找到两个CSV文件之间的差异。它提供了一种简单的方法来比较两个CSV文件的内容并识别一个文件中存在哪些记录,而不是另一个文件中存在。
笔记
在比较差异的CSV文件时,请确保将CSV提供更多条目。例如,如果CSV-1具有34个名称的列表,并且CSV-2的列表为40,则应将CSV-2设置为第二个通过的CSV路径,以便以预期显示差异。
您可以使用pip安装CSV-Compare:
pip install csv-compare-tool要在Python项目中使用CSV-Compare,请按照以下步骤操作。
重要的
在Python项目中作为软件包导入时,请确保删除连字符,以便包装读取csvcomparetool (有关更多信息,请参见PEP 8)
import csvcomparetool可选,您可以单独导入CSVComparer类
from csvcomparetool import CSVComparerCSVComparer对象 csv1_path = "path/to/first.csv"
csv2_path = "path/to/second.csv"
column = "identifier_column"
comparer = CSVComparer ( csv1_path , csv2_path , column ) if not comparer . validate_paths ():
print ( "CSV file paths are invalid. Please check the file paths and try again." )
return if not comparer . validate_columns ():
print ( "Provided column not found in CSV. Check the columns and try again." )
return differences = comparer . find_differences () for difference in differences :
print ( f"Record ' { difference } ' is present in CSV2 but not in CSV1." ) from csvcomparetool import CSVComparer
csv1_path = "path/to/first.csv"
csv2_path = "path/to/second.csv"
column = "identifier_column"
comparer = CSVComparer ( csv1_path , csv2_path , column )
if not comparer . validate_paths () or not comparer . validate_columns ():
print ( "CSV file paths are invalid, or the column identifier does not exist. Check the file paths and columns and try again." )
else :
differences = comparer . find_differences ()
for difference in differences :
print ( f"Record ' { difference } ' is present in CSV2 but not in CSV1." )首先,克隆该存储库到机器上的本地目录
git clone https://github.com/liquidz00/csv-compare.git导航到克隆的回购位置(您选择保存存储库的本地目录)
cd /path/to/repo/src/csvcomparetool/最后,运行以下命令
python cli.py /csv/path/one /csv/path/two columnidentifier