I have 2 pandas DataFrames:
df1:
c1 | c2 | x |
---|---|---|
1 | 1 | 1 |
2 | 1 | 4 |
1 | 2 | 1 |
2 | 2 | 4 |
and df2:
c1 | c2 | c3 |
---|---|---|
1 | 1 | 1 |
1 | 2 | 1 |
2 | 2 | 2 |
and I want to append the x
row to df2
like:
c1 | c2 | c3 | x |
---|---|---|---|
1 | 1 | 1 | 1 |
1 | 2 | 1 | 1 |
2 | 2 | 2 | 4 |
I tried to use join
, but because I don't have a unique index, it didn't work:
df1.set_index(['c1', 'c2'], inplace=True)
df2.set_index(['c1', 'c2'], inplace=True,drop=False)
df2=df2.join(df1)
df2:
c1 | c2 | c3 | x |
---|---|---|---|
1 | 1 | 1 | Nan |
1 | 2 | 1 | Nan |
2 | 2 | 2 | Nan |