I want to groupby 'id' column and add the value from the next row to the current row only for 'trip' column
How can I transform the first dataframe to second dataframe show below?
CodePudding user response:
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)