I have two Pandas Dataframes, which consist of the same columns and are partly filled with similar data. Each row in the dataframe has a unique id.
df1
ID A B C D
0 23149 -112.2 15 454 456
1 89799 -221.84 12 454
2 11589 339.93 48 564
3 67867 -855.5 13
4 7898 68.4 90
5 789 45.1 10
6 456 4564 12
df2 (before)
ID A B C D
0 23149 -112.2 15
1 23154 68.4 90
2 11589 339.93 48
3 97897 -855.5 13
4 89799 -221.84 12
I want to enrich the columns C and D in df2 with values from df1.
- ID, A and B should not be changed in df2
- If an ID exists in both dataframes the values for C and D should be added from df1.
In my example I expect a dataframe similar to this.
df2 (afterwards)
ID A B C D
0 23149 -112.2 15 454 456
1 23154 68.4 90
2 11589 339.93 48 564
3 97897 -855.5 13
4 89799 -221.84 12 454
How can I implement this conditional filling?