modin.pandas.Resampler.ffill¶
- Resampler.ffill(limit: Optional[int] = None) Union[DataFrame, Series] [source]¶
Forward fill values for missing resample bins.
- Parameters:
limit (int, optional) – This parameter is not supported and will raise NotImplementedError.
- Returns:
A
DataFrame
with values forward filled for missing resample bins.- Return type:
Examples
For Series: >>> lst1 = pd.to_datetime([‘2020-01-03’, ‘2020-01-04’, ‘2020-01-05’, ‘2020-01-07’, ‘2020-01-08’]) >>> ser1 = pd.Series([1, 2, 3, 4, 5], index=lst1) >>> ser1 2020-01-03 1 2020-01-04 2 2020-01-05 3 2020-01-07 4 2020-01-08 5 Freq: None, dtype: int64
>>> ser1.resample('1D').ffill() 2020-01-03 1 2020-01-04 2 2020-01-05 3 2020-01-06 3 2020-01-07 4 2020-01-08 5 Freq: None, dtype: int64
>>> ser1.resample('3D').ffill() 2020-01-03 1 2020-01-06 3 Freq: None, dtype: int64
>>> lst2 = pd.to_datetime(pd.Index(['2023-01-03 1:00:00', '2023-01-04', '2023-01-05 23:00:00', '2023-01-06', '2023-01-07 2:00:00', '2023-01-10'])) >>> ser2 = pd.Series([1, 2, 3, 4, None, 6], index=lst2) >>> ser2 2023-01-03 01:00:00 1.0 2023-01-04 00:00:00 2.0 2023-01-05 23:00:00 3.0 2023-01-06 00:00:00 4.0 2023-01-07 02:00:00 NaN 2023-01-10 00:00:00 6.0 Freq: None, dtype: float64
>>> ser2.resample('1D').ffill() 2023-01-03 NaN 2023-01-04 2.0 2023-01-05 2.0 2023-01-06 4.0 2023-01-07 4.0 2023-01-08 NaN 2023-01-09 NaN 2023-01-10 6.0 Freq: None, dtype: float64
>>> ser2.resample('2D').ffill() 2023-01-03 NaN 2023-01-05 2.0 2023-01-07 4.0 2023-01-09 NaN Freq: None, dtype: float64
For DataFrame:
>>> index1 = pd.to_datetime(['2020-01-03', '2020-01-04', '2020-01-05', '2020-01-07', '2020-01-08']) >>> df1 = pd.DataFrame({'a': range(len(index1)), ... 'b': range(len(index1) + 10, len(index1) * 2 + 10)}, ... index=index1) >>> df1 a b 2020-01-03 0 15 2020-01-04 1 16 2020-01-05 2 17 2020-01-07 3 18 2020-01-08 4 19
>>> df1.resample('1D').ffill() a b 2020-01-03 0 15 2020-01-04 1 16 2020-01-05 2 17 2020-01-06 2 17 2020-01-07 3 18 2020-01-08 4 19
>>> df1.resample('3D').ffill() a b 2020-01-03 0 15 2020-01-06 2 17
>>> index2 = pd.to_datetime(pd.Index(['2023-01-03 1:00:00', '2023-01-04', '2023-01-05 23:00:00', '2023-01-06', '2023-01-07 2:00:00', '2023-01-10'])) >>> df2 = pd.DataFrame({'a': range(len(index2)), ... 'b': range(len(index2) + 10, len(index2) * 2 + 10)}, ... index=index2) >>> df2 a b 2023-01-03 01:00:00 0 16 2023-01-04 00:00:00 1 17 2023-01-05 23:00:00 2 18 2023-01-06 00:00:00 3 19 2023-01-07 02:00:00 4 20 2023-01-10 00:00:00 5 21
>>> df2.resample('1D').ffill() a b 2023-01-03 NaN NaN 2023-01-04 1.0 17.0 2023-01-05 1.0 17.0 2023-01-06 3.0 19.0 2023-01-07 3.0 19.0 2023-01-08 4.0 20.0 2023-01-09 4.0 20.0 2023-01-10 5.0 21.0
>>> df2.resample('2D').ffill() a b 2023-01-03 NaN NaN 2023-01-05 1.0 17.0 2023-01-07 3.0 19.0 2023-01-09 4.0 20.0