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
.
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.