I have two dataframes that look like this:
df1
A B C
5 1 5
4 2 8
2 5 3
df2
A B C D
4 3 4 1
3 5 1 2
1 2 5 4
df1 and df2 share the same columns names except "D" which is only found in df2. What I would like to do is add D to df1 but fill all rows with "0"'s
In other words, if a column exists in df2 but it doesn't in df1, add that column to df1 but make all values in that column 0 (below)
df1
A B C D
5 1 5 0
4 2 8 0
2 5 3 0
I realize it would be very easy to add one column called "D" to df1 but this is just a dummy example when in reality I am dealing with much larger and many more dataframes. So, I am looking for a way to do this with a code I could implement in a loop or iteratively
addis getting confusing here. Seems like you simply want to create a column 'D' with the static value of 0 in df1, leaving everything else unchanged?