'How can I Optimize this algoritme with Python using Pandas?

Itereate two dataframe in same time and copy the target value if i found it

def test_get_value(df_f,df_s):
    k=0
    list=[]
    for i in df_f.index:
        val_f = df_f.at[i,'IssuedPostFKId']
        
        if val_f in df_s.Id.values:
            index_sent = df_s.index[df_s['Id'] == val_f].tolist()
            df_f.loc[i,'OutBoxId'] = index_sent
                #list.append(df_Sent.ID.index)
    #print(len(list))
            

        
%timeit test_get_value(df_MailBox,df_Mail_Sent)



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source