Skip to content
Advertisement

Join two columns of sequentially values

I have dataframe, where ‘A’ 1 – client, B – admin I need to merge messages in row with 1 sequentially and merge lines 2 – admin response sequentially across the dataframe.

JavaScript

I do not know how to do this

Advertisement

Answer

Create groups by consecutive values in B – trick compare shifted values with cumulative sum and aggregate first and join. Create helper column for posible pivoting in next step by DataFrame.pivot:

Solution working if exist pairs 1,2 in sequentially order with duplicates.

JavaScript
User contributions licensed under: CC BY-SA
3 People found this is helpful
Advertisement