I have two datasets that contains domain names:
df1:
varA     domains            
123     www.google.com   
456     www.ebay.com     
789     www.amazon.com   
101     www.nbc.com      
....
df2:
 urls            varB
www.cnn.com      xsd
www.ebay.com     wer
www.nbc.com      xyz
www.amazon.com   zyx
....
I need to populate urls values in df2 with varA values from df1 for the matching domains/urls, so the output would look like this:
 urls            varA   varB
www.ebay.com     456    wer
www.nbc.com      101    xyz
www.amazon.com   789    zyx
....
All of the domains in df2 that do not have a matching domain in df1 should be removed.
I have this code:
target_cols = ['domains', 'urls', 'varB', 'varA']
df2.merge(df1[target_cols], on='urls', how='inner')
The code is generating an error.
How do I fix it? Any alternative solutions that can work?
 
    