I have a Pandas dataframe as follows:
df =
open high low close
Timestamp
2014-01-07 13:18:00 874.67040 892.06753 874.67040 892.06753
2014-01-07 13:19:00 NaN NaN NaN NaN
2014-01-07 13:20:00 NaN NaN NaN NaN
2014-01-07 13:21:00 883.23085 883.23085 874.48165 874.48165
2014-01-07 13:22:00 NaN NaN NaN NaN
For each of the NaN's, they should take the value of the previous period's close.
Edit: I have tried using df.fillna(method='ffill') but it makes each NaN take values directly above it. I would like each NaN to take only the value of Close before it.
Using ffill yields:
open high low close
Timestamp
2014-01-07 13:18:00 874.67040 892.06753 874.67040 892.06753
2014-01-07 13:19:00 874.67040 892.06753 874.67040 892.06753
But I am looking for:
open high low close
Timestamp
2014-01-07 13:18:00 874.67040 892.06753 874.67040 892.06753
2014-01-07 13:19:00 892.06753 892.06753 892.06753 892.06753