0

I have a dataframe:

Test  Test2  Test3
a     d      1
b     d      4
a     s      5
a     d      2

I want to write a function that looks at all the rows and if the values in Test and Test2 are the same, it adds all the values in Test3 and creates this as a new row and deletes all the old ones with duplicates in Test and Test2. In this case, the final df would look like this:

Test  Test2  Test3
a     d      3
b     d      4
a     s      5

Is there a way to do this without looping through the df and deleting all the rows "manually"?

How would I handle additional columns using the code in the suggested post?

LizzAlice
  • 678
  • 7
  • 18
  • `How would I handle additional columns using the code in the suggested post?` can you be more specific? – jezrael Oct 25 '19 at 11:41
  • @jezrael When making the minimal example, I did not know that it would make a difference how many other columns there are. For example, I have two others and if I use the code in the other post, they are cut away. – LizzAlice Oct 25 '19 at 11:42
  • hmmm, I think reason is there are no numeric, the best is create better sample data with expected output – jezrael Oct 25 '19 at 11:43

0 Answers0