0

I want to check if the value in both datasets is equal. But the datasets are not in the same order so need to loop through the datasets.

Dataset 1 contract : enter image description here

Part number H50 H51 H53
ID001 1 1 1
ID002 1 1 1
ID003 0 1 0
ID004 1 1 1
ID005 1 1 1

data 2 anx : enter image description here

So the partnumber are not in the same order, but to check the value the partnumber needs to be equal from each file. Then if the part nr is the same, check if the Hcolumn is the same too. If both partnumber and the H(header)nr are the same, check if the value is the same.

Part number H50 H51 H53
ID001 1 1 1
ID003 0 0 1
ID004 0 1 1
ID002 1 0 1
ID005 1 1 1

Expecting outcome:

If the value 1==1 or 0 == 0 from both dataset -> change to TRUE. If the value = 1 in dataset1 but = 0 in dataset2 -> change the value to FALSE. and safe all the rows that contains FALSE value into an excel file name "Not in contract" If the value = 0 in dataset1 but 1 in dataset2 -> change the value to FALSE

Example expected outcome

Part number H50 H51 H53
ID001 TRUE TRUE TRUE
ID002 TRUE FALSE TRUE
ID003 TRUE FALSE FALSE
ID004 FALSE TRUE TRUE
ID005 TRUE TRUE TRUE

1 Answers1

0
df_merged = df1.merge(df2, on='Part number')
a = df_merged[df_merged.columns[df_merged.columns.str.contains('_x')]]
b = df_merged[df_merged.columns[df_merged.columns.str.contains('_y')]]
out = pd.concat([df_merged['Part number'], pd.DataFrame(a.values == b.values, columns=df1.columns[1:4])], axis=1)
out

    Part number H50 H51 H53
0   ID001   True    True    True
1   ID002   True    False   True
2   ID003   True    False   False
3   ID004   False   True    True
4   ID005   True    True    True