0

I have a data-frame like below and I want to group data based on second column. The table is unique on ColumnA.

Condition:

If a value in columnA appears in any row in columnB, add that value to the value from columnA corresponding to the value in columnB.

Input:

ColumnA ColumnB Values
AB12 CD34 30
CD34 NULL 40

Output:

ColumnA Values
AB12 70
mkrieger1
  • 19,194
  • 5
  • 54
  • 65
ash25
  • 113
  • 1
  • 11
  • What have you tried yourself? What library or framework are you looking (or allowed) to use? – Grismar Jan 05 '21 at 22:45
  • Please include sample(s) in text form that we can copy and paste for helping you, we don't want to type everything in... check out [How to make good reproducible pandas examples](https://stackoverflow.com/questions/20109391/how-to-make-good-reproducible-pandas-examples). – MarianD Jan 05 '21 at 23:06
  • I have not been able to formulate it with pandas yet, but my thought process in sql was to create something like this: SELECT t1.ColumnA, COALESCE(t1.ColumnB, t2.ColumnA) as columnC FROM t1 LEFT JOIN t1 AS t2 ON t1.ColumnA = t2.ColumnB; – ash25 Jan 05 '21 at 23:48

0 Answers0