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