Input: df as follows:
appl_id CNET CCON SCORE DER TOL_TNW
863793 42.6 4 752 0.4 1.8
863487 0 1 761.5 0.6 2.6
863487 0 1 770 0.6 2.6
863283 0 NaN 691 1.9 7.3
863283 0 5 691 NaN 7.3
900555 NaN NaN 650 0 NaN
Output Seek:
With respect to appl_id, different values in columns need to be concatenated to list and retain if values are similar.
appl_id CNET CCON SCORE DER TOL_TNW
863793 42.6 4 752 0.4 1.8
863487 0 1 [761.5,770] 0.6 2.6
863283 0 5 691 1.9 7.3
900555 NaN NaN 650 0 NaN
I have tried with
df.set_index('appl_id').T \
.apply(lambda x: x.shift(len(x) - x.index.get_loc(x.last_valid_index()) - 1)).T
but not solving my purpose. Can anyone have better suggestion how to do this?