I am working with huge volume of data and trying to map values from two dataframe. Looking forward for better Time complexity.
Here I am trying to match Code from df2 which are in df1 and take MLC Code from df1 if values match.
df1
| Code | MLC Code |
|---|---|
| 1 | 8 |
| 2 | 66 |
| 8 | 62 |
| 4 | 66 |
df2
| Code |
|---|
| 1 |
| 2 |
| 3 |
| 4 |
| 4 |
| 8 |
Result df
| Code | MLC Code |
|---|---|
| 1 | 8 |
| 2 | 66 |
| 3 | NA |
| 4 | 62 |
| 4 | NA |
| 8 | 66 |
Here is the code I am using to perform this task but it take lot of time to compute.
for i, j in enumerate(df2["Code"]):
for x, y in enumerate(df1["Code"]):
if j == y:
df2["MLC Code"][i] == df1["MLC Code"][x]