vendredi 21 septembre 2018

in pandas how to iterate through two data frames based on same ID

pandas

I have two data frames and want to do a nested loop.

I want to iterate of each row from df1 and select col1 (id) and col2.

Then, it will take the ID and iterate through df2 and check if the row has the same ID and then compare column from df1 with column in df2

if col2 in df1 matches col3 in df2, it will return True and append that to the row of df1.

df1
col1    col2   col3
 01      A     True
 02      D     True
 03      Z     False

df2
col1    col2   col3
 01      A      A
 02      B      A
 02      D      F
 02      C      D
 02      D      V
 03      X      W
 03      E      X

Aucun commentaire:

Enregistrer un commentaire