I’m having a question on python. I’m trying to compare two dataframes and check which elements are different and insert them into another dataframe. So here are my dataframes. df1:
PN Stock WHS Cost 1111 1 VLN 0.2 1111 2 VLN 0.2 1115 1 KNS 0.5
PN Stock WHS Cost Time 1111 1 VLN 0.2 15:00 1111 3 VLN 0.2 16:00
So the idea is to add to df1 the data from df2 that is not yet in df1; line 2 in df2 does not exist in df1 so I want to insert it.
How should i write code to find not existing line so that I could insert it?
I have tried:
for index, row in df1.iterrows(): if df2[(df2['PN']==row['PN']) & (df2['Stock'] ==row['Stock']) & (df2['Whs'] = row['Whs']) & (df2['Cost']==row['Cost'])].empty print row['PN']
To check which rows to update but i get basically all rows printed, not the ones that do not match. How can I solve this please? Is it possible to use somehow ‘IN’ function, comparing each df1 line with whole df2???