Merge two python pandas data frames of different length + sum common values

后端 未结 1 2003
南旧
南旧 2021-01-23 07:16

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

相关标签:
1条回答
  • 2021-01-23 07:55

    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

    0 讨论(0)
提交回复
热议问题