0

this is my code to iterate two tables simultanous

for i in df_MailBox_SentService.index :
    val_s = df_MailBox_SentService.at[i,'MailId']
    for j in df_TBL_SentMail.index :
        if val_s == df_TBL_SentMail.at[j,'ID']:
            df_MailBox_SentService.at[i,'UnifiedMailNumber']=df_TBL_SentMail.at[j,'MailNbr']
       
5
  • 1
    please fix your indentations Commented Feb 1, 2023 at 15:10
  • 1
    you are assigning values to a position determined exclusively by i df_MailBox_SentService.at[i,'UnifiedMailNumber'] but then you have an inner loop that will keep overwriting on that position every time the conditional is triggered (since j is not used to determine the position to write to). The loops don't make much sense to me, unless the conditional is guaranteed to trigger only once, in that case you should break the inner loop to improve performance Commented Feb 1, 2023 at 15:15
  • It looks like you are using pandas. In pandas you can join two dataframes, so you don't need to loop over them with for loops. If you need help with that, provide a full code example - including code to create the dataframes - so you can get help. Also useful, say how big the big tables are. Commented Feb 1, 2023 at 15:21
  • the two dataframe is 1 million record and 100k records Commented Feb 1, 2023 at 15:25
  • are you looking to stackoverflow.com/questions/37697195/… Commented Feb 1, 2023 at 16:03

1 Answer 1

1

Try this:

mask = df_MailBox_SentService['MailId'] == df_TBL_SentMail['ID']
df_MailBox_SentService.loc[mask, 'UnifiedMailNumber'] = df_TBL_SentMail.loc[mask, 'MailNbr']
Sign up to request clarification or add additional context in comments.

1 Comment

this is the error : Can only compare identically-labeled Series objects

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.