I have two dataframes df1 and df2. I would like to create a third dataframe that sums elements of the two with the same name.
I tried something like this:
df1 = pd.DataFrame(np.array([['a', 5, 9],['b', 4, 61],['c', 24, 9]]), columns=['name', 'attr1', 'attr2'])
df2 = pd.DataFrame(np.array([['a', 5, 19],['b', 14, 16],['c', 4, 9]]) columns=['name', 'attr1', 'attr2'])
df5=pd.merge(df1, df2, on=['name']).set_index(['name']).sum(axis=1)
But it does not seem to do the job. The new df3 corresponds to the sum of the entire rows while I need an element by element sum.