I want to combine 2 similar dataframes. I I have checked several websites but couldn't find an answer to my question.
df1 = DataFrame({'A': ['A0', 'A1', 'A2', 'A3'],
'B': ['B0', 'B1', 'B2', 'B3'],
'C': ['C0', 'C1', 'C2', 'C3'],
index=[0, 1, 2])
df2 = DataFrame({'A': ['A0', 'A1', 'A4', 'A3'],
'B': ['B0', 'B1', 'B4', 'B3'],
'D': ['D0', 'D1', 'D4', 'D3']},
index=[0, 1, 2])
I want to have
df3 = DataFrame({'A': ['A0', 'A1', 'A3'],
'B': ['B0', 'B1', 'B3'],
'C': ['C0', 'C1', 'C3'],
'D': ['D0', 'D1', 'D3'].
index=[0, 1, 2, 3])
Essentially I combine 2 dataframes, adding column D to the first dataframe. But I omit any rows that won't have values for both C and D, like row 2 and 4. I have tried append and concat but it just gives me all the columns and all the rows stacked on top of each other.
Thanks!