I need to be able to add the values of two dataframes with the same structure together and form a new dataframe as a result.
e.g. DF1 + DF2 = DF3
DF1
+------------+----+----+----+
| date | A | B | C |
+------------+----+----+----+
| 2017-01-01 | 24 | 15 | 4 |
| 2017-01-02 | 31 | 10 | 12 |
| 2017-01-03 | 9 | 47 | 3 |
+------------+----+----+----+
DF2
+------------+----+----+----+
| date | A | B | C |
+------------+----+----+----+
| 2017-01-01 | 4 | 12 | 63 |
| 2017-01-02 | 23 | 0 | 31 |
| 2017-01-03 | 61 | 22 | 90 |
+------------+----+----+----+
DF3
+------------+----+----+----+
| date | A | B | C |
+------------+----+----+----+
| 2017-01-01 | 28 | 27 | 67 |
| 2017-01-02 | 64 | 10 | 43 |
| 2017-01-03 | 70 | 69 | 93 |
+------------+----+----+----+
I've been trying to work out how to do this but i'm getting a TypeError
TypeError: unsupported operand type(s) for +: 'datetime.date' and 'datetime.date'
when trying to do:
df3 = df1.add(df2, fill_value=0)
I'm sure i'm missing something simple as it appears to be trying to add the first columns (which is a date and the column I want to match on to add together the values for all other columns) but any help would be greatly appreciated.
df3 = pd.concat([df1, df2]).groupby('date').sum().reset_index()