I have a dataframe like this
A B
2018-02-01 00:00:00 5.592860 2.789900
2018-02-01 00:15:00 5.288981 2.054017
2018-02-01 00:30:00 5.319665 2.232686
2018-02-01 00:45:00 5.198657 2.236154
2018-02-01 01:00:00 5.018134 2.064312
The Column A will not have any missing values, but column B will be having.
I have another list like this of length 12 named forecasts
[0.09545173 0.09946214 0.10596157 0.12075519 0.14446978 0.16848372
0.20479251 0.23742175 0.26723814 0.29389328 0.30628437 0.3140854 ]
I want to loop through each row in the dataframe and check whether next 12 rows have any nan. If nan is present, replace that value from the corresponding index from the list.
If the 2nd row from the current index is nan then replace that nan by forecasts[2]
To make things more clear,
I will have a dataframe with data like I said the question. There may be misses in the column B but not A. I will have a list of 12 location for each timestamp. The list being named forecast will have the forecasted value of present timestamp in forecasts[0] and 11th timestamp from now in forecast[11]. I want to loop though each timestamp in the dataset, check whether any nan is present in the next 12 locations of the dataframe in the column B.
If there are nan, then replace it with the forecast.
How can I do this easily with pandas.?
forecasts. It seems to pop up from nowhere? I think that is the list but...I don't know now.