Pandas/Python - comparing two columns for matches not in the same row
To clarify, this question is about comparing two columns to check if the 3-letter combinations match.
So, I would approach this in the following manner:
# Extract the 3-letter combinations from column a
df3[&quot;a normalised&quot;] = df3[&quot;a&quot;].str[:3]

# Then check if what is in `a normalised` is in column b 

b_matches = list(df3[df3[“b”].isin(list(df3[“a normalised”]))][“b”].unique())
df3.loc[:, &quot;match&quot;] = False

b_match_idx = df3[df3[&quot;a normalised&quot;].isin(b_matches)].index

df3.at[np.array(b_match_idx),&quot;match&quot;] = True


EDIT: The parentheses have now been resolved. Also the .loc warning can now be mitigated.