0

I am using python and pandas.

I have:

df1:              df2:
|index | ID |     |index | ID  | name  |
|  1   | 34 |     |  1   |  35 | Astri |
|  2   | 35 |     |  2   |  36 | Carlos|
|  3   | 36 |     |  3   |  34 | Xim   |

So, i want somthing like this using isin():

df1:
    |index | ID | name   |
    |  1   | 34 | Xim    |
    |  2   | 35 | Astri  |
    |  3   | 36 | Carlos |

The function I am using is this. I can tell if the ID of df1 exists in df2, but I am unable to assign the 'name' column of df2, to df1

df1 = df1[df1.ID.isin(df2.ID)]

I don't want to have to iterate using a FOR and iterrows(), because I will apply this to a dataset of eight million records. Thank you!

Mhul
  • 1
  • This case is hypothetical, the real columns are purchased sources with different columns. Basically what I need is the explained. – Mhul Mar 20 '20 at 15:12

1 Answers1

0

This is merging two dataframes together. consider merge or join.

df1 = df1.merge(df2, how = 'left', on = 'ID')

harmony
  • 91
  • 7
  • Thanks for the quick reply. Regarding your code, I need to condition by the ID, if I paste the df2 next to df1 the IDs will not match because in the original source they are document ID – Mhul Mar 20 '20 at 16:56