I have a data frame like as shown below
df = pd.DataFrame({'person_id': [11,11,11,21,21,21,31,31,31,31,31],
'time' :[-1,5,17,11,25,39,46,4,100,150,1],
'value':[101,102,121,120,143,153,160,170,96,97,99]})
What I would like to do is
a) FIll in the missing time by generating a sequence number (ex:1,2,3,4) and copy the value (for all other columns) from the previous row
I was trying something like below
df.groupby(['person_id']).cumcount() + 1
df['sequence'] = g.cumcount() + 1
But this doesn't help me get the expected output
I expect my output to be like as shown below (SAMPLE OF 1 SUBJECT IS SHOWN BELOW)
