Skip to content Skip to sidebar Skip to footer

Move Last Value To First Value

In this dataframe, I would like to move the value in the last duplicate to the first duplicate and set others to NaT. ID OutBedTime DateOutBed 1 16/05/2018 0:17 16/05/

Solution 1:

Let us try

L1 = s1.groupby(['ID', 'DateOutBed'])['OutBedTime'].transform('last')
s1['TimeOutBedFinal'] = L1.mask(s1[['ID', 'DateOutBed']].duplicated())

Post a Comment for "Move Last Value To First Value"