我有两个 csv 文件都包含两列。
第一个有产品 ID,第二个有序列号。
我需要查找第一个 csv 中的所有序列号,并在第二个 csv 上找到匹配项。结果报告,将有匹配的序列号,以及来自每个 csv 的相应产品 ID,在单独的列中我确实修改了下面的代码,没有运气。
你会如何处理这个问题?
import pandas as pd
A=set(pd.read_csv("c1.csv", index_col=False, header=None)[0]) #reads the csv, takes only the first column and creates a set out of it.
B=set(pd.read_csv("c2.csv", index_col=False, header=None)[0]) #same here
print(A-B) #set A - set B gives back everything thats only in A.
print(B-A) # same here, other way around.
原文由 user7609771 发布,翻译遵循 CC BY-SA 4.0 许可协议
我想你需要
merge
: