0

I have two dataframes, df1 and temp. I want to compare a common column, 'OrderId' values in the two dataframes and insert the value of a different column, 'Order_Time' of temp into 'Time' column of df1.

df1 and temp sample

Above is the sample of the df1 and temp dataframes. In df1, some of the values of column Time are dashed '-', Based on the 'OrderId' I want to assign the value of 'Order_Time' from temp to 'Time' in df1.

I have already tried with break and continue statements, but the loop stops after inserting the values in a few rows. Also tried replacing '&' with 'and', still no change.

row1_iterator = df1.iterrows()

row2_iterator = temp.iterrows()

for i, row1 in row1_iterator:

    if ((row1['Status']=='MPF') & (row1.Time=='-')):

        for j, row2 in row2_iterator:

            if (row1['OrderId'] == row2['OrderId']):
                    df1.at[i,'Time'] = row2['Order_Time']

I want this loop to run completely for all the rows of df1. Else, if there is any other optimum way of doing it, I'd like to know that as well.

S93G
  • 1
  • 1
  • 2
    You should sure `and` instead of `&` – jkhadka Sep 10 '19 at 06:26
  • Tried that as well, still not working. – S93G Sep 10 '19 at 06:28
  • 1
    can you post an example of `df1` and `temp`? Also what changes do you exactly want on them as an example? It is always suggested that you post a minimal reproducible example instead of just posting codes. – jkhadka Sep 10 '19 at 06:29
  • Does the edit help? It is my first time posting a question, so a little out of my depth here. Thanks for the suggestions though! – S93G Sep 10 '19 at 06:41
  • It is better to just paste a part of data here in the question, so others can test your code and figure out the problem. – jkhadka Sep 10 '19 at 07:51

0 Answers0