I would like to add multiple multi index data frames together, with differing columns, but if there are similar columns/cells, then the values will be added together.
Constraints:
- There are up to n dataframes to be merged and summed
- Within the code, you cannot call the multi index columns and index (should be general)
Example:
df1
Category | A | B | C |
Region | AC| AD| AK|
0-5 years | 2 | 3 | 4 |
5-10 years | 1 | 2 | 5 |
10-12 years| 2 | 0 | 2 |
df 2
Category | A | B | D |
Region | AC| AD| AM|
0-5 years | 1 | 4 | 1 |
5-10 years | 2 | 5 | 1 |
10-12 years| 3 | 6 | 0 |
Desired outcome:
Category | A | B | C | D |
Region | AC| AD| AK| AM|
0-5 years | 3 | 7 | 4 | 1 |
5-10 years | 3 | 7 | 5 | 1 |
10-12 years| 5 | 6 | 2 | 0 |
Any help would be greatly appreciated, thanks in advance!