I have two dataframes where each of them contain a column called 'ID'. The challenge is to compare these IDs and then to assign the right values from one dataframe to the other.
Namely, I want to add a new column to the first dataframe while this column contains the new information from dataframe 2 but in the right order. The order is determined by the 'ID'.
Since the dataframes contain each about 100k rows, two for loops takes too long to find and replace the values. How can I speed up the process?
My first approach:
for i in range1:
for j in range2:
if df1["ID"][i] == df1["ID"][j]:
df1['feature'][i] = df2['feature'][j]
Here I created the column feature for df1 too. I thought about deleting the row after each replacement of the right value to improve this process but it did not work as expected.