I have a a very large dataset containing id and data points of time series (with some missing values). The following is just an example.
I will need to create a lag variable for both group which of course will create NaN for the first observation for each group. I would like to assign the next available value to the created NaN specifically but leave other missing value untouched for later manipulation.
id time value lag_value
A 2000 10 NaN # I want this to be 10, the next available value
A 2001 11 10
A 2002 NaN 11
A 2003 14 NaN
A 2004 10 14
Edit:
I think it would be cleaner to use first_valid_index
to assign the next available value, see Pandas - find first non-null value in column