两个csv文件之间的差异

hkmswyz6  于 2023-01-28  发布在  其他
关注(0)|答案(1)|浏览(193)

我在确定两个csv文件之间的区别时遇到了问题。我已经逐行比较了它们,它们完全相同(as text).当我使用terminal diff查看差异时,它告诉我每一行都不一样,检查完每个文件的大小后,我意识到两个文件之间字节数的差异与每个文件中的行数相同。我怀疑我每行漏掉了一个字节。然而,正如我提到的,如果我把它们作为文本文件打开,我看不出有什么区别。2有没有什么工具可以让我比较它们,知道它们有什么区别?

vcirk6k6

vcirk6k61#

对于这个文件,其中一个文件中可能存在间距差异或一些Unicode字符,这可能会导致您出现问题。
我有一个python脚本,它给了我两个文件之间的区别,希望这对你有帮助。

import csv

def main():
    old_file = 'oldfile.txt'
    new_file = 'newfile.txt'

    # Create sets to store the unique values from each file
    old_set = set()
    new_set = set()

    # Open the old file and add the first column of each row to the old_set
    with open(old_file, 'r') as f:
        reader = csv.reader(f)
        for row in reader:
            old_set.add(row)

    # Open the new file and add the first column of each row to the new_set
    with open(new_file, 'r') as f:
        reader = csv.reader(f)
        for row in reader:
            new_set.add(row)

    
    # Print the missing values
    print(missing_values)

if __name__ == "__main__":
    main()

如果你没有看到任何打印出来的东西,试着颠倒文件名,这可能是一种方式或其他。希望这能有所帮助

相关问题