sum numbers in two dataframes based on their intersecting indexes

Question:

i have 2 dataframes with some common index and some that are not:

df1
   DATA
1     1
2     2
3     3
4     4
5     5

df2
   DATA
3     3
4     4
5     5
6     6
7     7

I want to sum/take max (i actually need both for different cols) them, and consider missing indexes as 0.
In this example the result should be:

df_results
   DATA
1     1
2     2
3     6
4     8
5    10
6     6
7     7

where 3,4,5 were summed, but the rest remained the same.

Thx!

Asked By: Guy Barash

||

Answers:

Try this:

combined = df1.add(df2, fill_value=0)
Answered By: gtomer
Categories: questions Tags: ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.