How to add multiple dataframes together

  dataframe, pandas, python, python-3.x

I would like to add multiple data frames together, with differing columns, but if there are similar columns/cells, then the values will be added together.

Here is an example:

Input:

df1

Region Code (Index) Number of police stations Amount of crime Average Age
B 2 2 35
A 1 5 45
C 3 5 56

df2

Region Code (Index) Number of police stations Amount of crime
B 5 2
A 3 5

Expected output:

Region Code (Index) Number of police stations Amount of crime Average Age
B 7 4 35
A 4 10 45
C 3 5 56

Any indication of how to do it or maybe a better way to structure would be greatly appreciated!

Source: Python Questions

LEAVE A COMMENT