Assume I have a pandas series with several consecutive NaNs. I know fillna
has several methods to fill missing values (backfill
and fill forward
), but I want to fill them with the closest non NaN value. Here's an example of what I have:
s = pd.Series([0, 1, np.nan, np.nan, np.nan, np.nan, 3])
And an example of what I want:
s = pd.Series([0, 1, 1, 1, 3, 3, 3])
Does anyone know I could do that?
Thanks!