Vectorized method to find matching values between two columns
you could use set to get the intersection (it has a complexity logarithmic in the size of the sets a and b)

 a = set(df['A'])
 b = set(df['B'])
 a.intersection(b)