- API reference
- Resampling
- pandas.core....
pandas.core.resample.Resampler.bfill#
- finalResampler.bfill(limit=None)[source]#
Backward fill the new missing values in the resampled data.
In statistics, imputation is the process of replacing missing data withsubstituted values[1]. When resampling data, missing values mayappear (e.g., when the resampling frequency is higher than the originalfrequency). The backward fill will replace NaN values that appeared inthe resampled data with the next value in the original sequence.Missing values that existed in the original data will not be modified.
- Parameters:
- limitint, optional
Limit of how many values to fill.
- Returns:
- Series, DataFrame
An upsampled Series or DataFrame with backward filled NaN values.
See also
bfillAlias of backfill.
fillnaFill NaN values using the specified method, which can be ‘backfill’.
nearestFill NaN values with nearest neighbor starting from center.
ffillForward fill NaN values.
Series.fillnaFill NaN values in the Series using the specified method, which can be ‘backfill’.
DataFrame.fillnaFill NaN values in the DataFrame using the specified method, which can be ‘backfill’.
References
Examples
Resampling a Series:
>>>s=pd.Series([1,2,3],...index=pd.date_range('20180101',periods=3,freq='h'))>>>s2018-01-01 00:00:00 12018-01-01 01:00:00 22018-01-01 02:00:00 3Freq: h, dtype: int64
>>>s.resample('30min').bfill()2018-01-01 00:00:00 12018-01-01 00:30:00 22018-01-01 01:00:00 22018-01-01 01:30:00 32018-01-01 02:00:00 3Freq: 30min, dtype: int64
>>>s.resample('15min').bfill(limit=2)2018-01-01 00:00:00 1.02018-01-01 00:15:00 NaN2018-01-01 00:30:00 2.02018-01-01 00:45:00 2.02018-01-01 01:00:00 2.02018-01-01 01:15:00 NaN2018-01-01 01:30:00 3.02018-01-01 01:45:00 3.02018-01-01 02:00:00 3.0Freq: 15min, dtype: float64
Resampling a DataFrame that has missing values:
>>>df=pd.DataFrame({'a':[2,np.nan,6],'b':[1,3,5]},...index=pd.date_range('20180101',periods=3,...freq='h'))>>>df a b2018-01-01 00:00:00 2.0 12018-01-01 01:00:00 NaN 32018-01-01 02:00:00 6.0 5
>>>df.resample('30min').bfill() a b2018-01-01 00:00:00 2.0 12018-01-01 00:30:00 NaN 32018-01-01 01:00:00 NaN 32018-01-01 01:30:00 6.0 52018-01-01 02:00:00 6.0 5
>>>df.resample('15min').bfill(limit=2) a b2018-01-01 00:00:00 2.0 1.02018-01-01 00:15:00 NaN NaN2018-01-01 00:30:00 NaN 3.02018-01-01 00:45:00 NaN 3.02018-01-01 01:00:00 NaN 3.02018-01-01 01:15:00 NaN NaN2018-01-01 01:30:00 6.0 5.02018-01-01 01:45:00 6.0 5.02018-01-01 02:00:00 6.0 5.0