Skip to content Skip to sidebar Skip to footer

Merge Two Python Pandas Data Frames Of Different Length + Sum Common Values

I have the following problem: I have two pandas data frames of different length containing some rows that have common values and some that are different like this: df1 s1 s2

Solution 1:

Solution

df1.add(df2, fill_value=0)

or

df1.add(df2, fill_value=0).astype(int)

This does exactly what you want using arguments intended to solve this exact problem. I added astype(int) at the end to preserve int

Post a Comment for "Merge Two Python Pandas Data Frames Of Different Length + Sum Common Values"