Fill NaN values by propagating values backward *Requires bottleneck.* Parameters ---------- dim : str Specifies the dimension along which to propagate values when filling. limit : int or None, default: None The maximum num
(self, dim: Hashable, limit: int | None = None)
| 3767 | return ffill(self, dim, limit=limit) |
| 3768 | |
| 3769 | def bfill(self, dim: Hashable, limit: int | None = None) -> Self: |
| 3770 | """Fill NaN values by propagating values backward |
| 3771 | |
| 3772 | *Requires bottleneck.* |
| 3773 | |
| 3774 | Parameters |
| 3775 | ---------- |
| 3776 | dim : str |
| 3777 | Specifies the dimension along which to propagate values when |
| 3778 | filling. |
| 3779 | limit : int or None, default: None |
| 3780 | The maximum number of consecutive NaN values to backward fill. In |
| 3781 | other words, if there is a gap with more than this number of |
| 3782 | consecutive NaNs, it will only be partially filled. Must be greater |
| 3783 | than 0 or None for no limit. Must be None or greater than or equal |
| 3784 | to axis length if filling along chunked axes (dimensions). |
| 3785 | |
| 3786 | Returns |
| 3787 | ------- |
| 3788 | filled : DataArray |
| 3789 | |
| 3790 | Examples |
| 3791 | -------- |
| 3792 | >>> temperature = np.array( |
| 3793 | ... [ |
| 3794 | ... [0, 1, 3], |
| 3795 | ... [0, np.nan, 5], |
| 3796 | ... [5, np.nan, np.nan], |
| 3797 | ... [3, np.nan, np.nan], |
| 3798 | ... [np.nan, 2, 0], |
| 3799 | ... ] |
| 3800 | ... ) |
| 3801 | >>> da = xr.DataArray( |
| 3802 | ... data=temperature, |
| 3803 | ... dims=["Y", "X"], |
| 3804 | ... coords=dict( |
| 3805 | ... lat=("Y", np.array([-20.0, -20.25, -20.50, -20.75, -21.0])), |
| 3806 | ... lon=("X", np.array([10.0, 10.25, 10.5])), |
| 3807 | ... ), |
| 3808 | ... ) |
| 3809 | >>> da |
| 3810 | <xarray.DataArray (Y: 5, X: 3)> Size: 120B |
| 3811 | array([[ 0., 1., 3.], |
| 3812 | [ 0., nan, 5.], |
| 3813 | [ 5., nan, nan], |
| 3814 | [ 3., nan, nan], |
| 3815 | [nan, 2., 0.]]) |
| 3816 | Coordinates: |
| 3817 | lat (Y) float64 40B -20.0 -20.25 -20.5 -20.75 -21.0 |
| 3818 | lon (X) float64 24B 10.0 10.25 10.5 |
| 3819 | Dimensions without coordinates: Y, X |
| 3820 | |
| 3821 | Fill all NaN values: |
| 3822 | |
| 3823 | >>> da.bfill(dim="Y", limit=None) |
| 3824 | <xarray.DataArray (Y: 5, X: 3)> Size: 120B |
| 3825 | array([[ 0., 1., 3.], |
| 3826 | [ 0., 2., 5.], |