Search code examples
pythondataframemergerow

How can i merge rows according to column name


I want "an b column value" add to "other b column value" which are same "a" column values

for python ↓↓↓

Column A Column B
title1 15
title2 12
title2 18
title3 8
title3 13
title4 7

I have this dataframe ↑

How can i transform to this one ↓

Column A Column B
title1 15
title2 30
title3 21
title4 7

Solution

  • Solution:

    Pandas has this built in functionality by combining groupby and sum together, for example

    df.groupby("Column A").sum()