Filling missing values in case of the market index data
Hello,
Not a question. Tried a different way of filling up missing values.
https://learn.365datascience.com/courses/time-series-analysis-in-python/filling-missing-values/
Module4, Time Series, Filling missing values.
The instructor suggested we could use ffil, bfill or column mean() to fill nikkei.
I took the mean of ffil and bfill and filled the nikkei market index values.
Regards
Hi Rajya,
thanks for reaching out and for the suggestion, it's great to have feedback and also learn from our students :)
Best,
365 Eli
Hi Rajya,
I was thinking of the sam idea
However, is there any way you know to do this without a for loop?
I followed this suggestion of Rajya, and with the help of AI, I used the ff. to fill in the missing values accordingly
# Average of ffill and bfill (leaves edge NaNs as NaN)
df_comp_nikkei_filled = (df_comp.nikkei.ffill() + df_comp.nikkei.bfill()) / 2
df_comp.nikkei = df_comp_nikkei_filled
Since all columns in the DataFrame are numeric and if we want edge NaNs to remain NaN (or you ), we can just compute the average directly as given above. This was the case for this dataset.
If ever we want to fill edge NaNs which remain afterward, we can run the ff. additionally:
# Optional: fill any remaining edge NaNs using whichever fill succeeded
df_comp_nikkei_filled = df_comp_nikkei_filled.fillna(df_comp.nikkei.ffill()).fillna(df_comp.nikkei.bfill())
df_comp.nikkei = df_comp_nikkei_filled
