Reputation: 513
I have a dataframe d1 with multiindex of col1 and col2:
col3 col4 col5
col1 col2
1 2 3 4 5
2 3 4 5 6
And another dataframe d2 with exact same structure:
col3 col4 col5
col1 col2
20 30 40 50 60
2 3 44 55 66
How to do d1.append(d2), to make it become, which override the previous keys:
col3 col4 col5
col1 col2
1 2 3 4 5
20 30 40 50 60
2 3 44 55 66
Upvotes: 0
Views: 52
Reputation: 10960
You could use pandas.concat
with keep last
pd.concat([df1, df2]).groupby(level=[0, 1]).last()
@BENY's answer is more user friendly and readable.
Upvotes: 1