我有两个 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.
我想你需要merge:
A = pd.DataFrame({'product id': [1455,5452,3775],
'serial number':[44,55,66]})
print (A)
B = pd.DataFrame({'product id': [7000,2000,1000],
'serial number':[44,55,77]})
print (B)
print (pd.merge(A, B, on='serial number'))
product id_x serial number product id_y
0 1455 44 7000
1 5452 55 2000
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)