0

Actually I am writing a script to find matched records using df1 and df2. Now I am doing this by iterating both df1 and df2 in O N^2.

for i,row1 in df1.iterrows:

   for j,row2 in df2.iterrows:

      if row1['fname'] == row2['fname'] 
        and row1['lname'] == row2['lname'] 
        and row1['email'] == row2['email']:
        #matched

I want to make it in more efficient way. Anyone can guide me which algorithm or Python thing I can use for it.

1 Answer 1

1

Consider using merge.

pd.merge(df1, df2, on=(['fname','lname','email']), how='inner')
Sign up to request clarification or add additional context in comments.

1 Comment

@U.Malik merge command joins both dataframes df1 and df2 on 3 columns fname,lname,email using inner join. This will basically return only those records which are present in both dataframes. Let me know if need further explanation.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.