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?

2 Answers 2

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()
Sign up to request clarification or add additional context in comments.

Comments

0

Use this method:

pd.concat([df1, df2]).groupby(['Name']).sum().reset_index()

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.