KGBeans KGBeans - 1 month ago 14
Python Question

Matching columns from multiple dataframes in pandas

I have 2 dataframes with a column of ['Names'] and ['Addresses']. I would like to get pandas to print the row in the second dataframe if it matches the name and address from the first.

Answer

consider d1 and d2

d1 = pd.DataFrame(dict(Names=list('ABCDEFG'),
                       Addressess=[1, 2, 3, 4, 5, 6, 7]))
d1

enter image description here

d2 = pd.DataFrame(dict(Names=list('FGHIJ'),
                       Addressess=[6, 7, 8, 9, 10]))
d2

enter image description here

then use merge

d2.merge(d1)

enter image description here