0

I have two dataframes with similar structure like follows:

df0
No. Name    PropNO  PropAmt
1   XYZ     -       - 
2   ABC     1077    34.90
3   GHI     -       - 
    Total   1077    34.90

df1
No. Name    PropNO  PropAmt
1   XYZ     2       0.6 
2   ABC     23      0.1
3   GHI     5       0.3 
    Total   30      1.0

I want output like:

No. Name    PropNO  PropAmt
1   XYZ     2       0.6 
2   ABC     1100    35.0
3   GHI     5       0.3 
    Total   1107    35.9

I have .add() but it also merge the Name column as well. Is there a better way to do it?

abhi1610
  • 721
  • 13
  • 28

2 Answers2

0

Use concat with aggregate sum:

dfs = [df1, df2]
#if necessary
#dfs = [df.replace('-', np.nan) for df in dfs]
df = pd.concat(dfs).groupby('Name', as_index=False).sum()
jezrael
  • 822,522
  • 95
  • 1,334
  • 1,252
0

Use this method:

pd.concat([df1, df2]).groupby(['Name']).sum().reset_index()
Subbu VidyaSekar
  • 2,503
  • 3
  • 21
  • 39