I have 2 dataframes:
df1 = pd.DataFrame(
[
(73, 15, 'update1', 1, 'foo'),
(63, 64, 'update2', 2, 'bar'),
(56, 72, 'update3', 3, 'foo'),
],
columns=['A', 'B', 'C', 'D', 'E'],
)
and
df2 = pd.DataFrame(
[
(73, 15, 'new1', 2, 'foo'),
(63, 64, 'new2', 3, 'bar'),
(56, 72, 'new3', 1, 'foo'),
],
columns=['A', 'B', 'C', 'D', 'E'],
)
I am looking for a way to join these 2 dataframes on column D and then update the column C of df1 so as to match the value of column C in df2.
Final Result:
df1 = pd.DataFrame(
[
(73, 15, 'new3', 1, 'foo'),
(63, 64, 'new1', 2, 'bar'),
(56, 72, 'new2', 3, 'foo'),
],
columns=['A', 'B', 'C', 'D', 'E'],
)
Any help is appreciated.
What I have tried so far?
Run a for loop and update the values in df1 by finding the corresponding value of column c in df2.