'how to add the value from the next row to the current row

I want to group by id column and add the value from the next row to the current row only for the trip column How can I transform the first data frame to the second data frame shown below?

enter image description here

enter image description here



Solution 1:[1]

I am not sure if the only thing requested is to concatenate the trip ID of the next row to the current row but if it is, would you consider using shift(-1) ?

df['newtrip']=df['trip']+'-'+df['trip'].shift(-1)

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Daniel Weigel