MCPcopy Index your code
hub / github.com/pydata/xarray / bfill

Method bfill

xarray/core/dataset.py:6727–6790  ·  view source on GitHub ↗

Fill NaN values by propagating values backward *Requires bottleneck.* Parameters ---------- dim : Hashable Specifies the dimension along which to propagate values when filling. limit : int or None, optional The maximum num

(self, dim: Hashable, limit: int | None = None)

Source from the content-addressed store, hash-verified

6725 return new
6726
6727 def bfill(self, dim: Hashable, limit: int | None = None) -> Self:
6728 """Fill NaN values by propagating values backward
6729
6730 *Requires bottleneck.*
6731
6732 Parameters
6733 ----------
6734 dim : Hashable
6735 Specifies the dimension along which to propagate values when
6736 filling.
6737 limit : int or None, optional
6738 The maximum number of consecutive NaN values to backward fill. In
6739 other words, if there is a gap with more than this number of
6740 consecutive NaNs, it will only be partially filled. Must be greater
6741 than 0 or None for no limit. Must be None or greater than or equal
6742 to axis length if filling along chunked axes (dimensions).
6743
6744 Examples
6745 --------
6746 >>> time = pd.date_range("2023-01-01", periods=10, freq="D")
6747 >>> data = np.array(
6748 ... [1, np.nan, np.nan, np.nan, 5, np.nan, np.nan, 8, np.nan, 10]
6749 ... )
6750 >>> dataset = xr.Dataset({"data": (("time",), data)}, coords={"time": time})
6751 >>> dataset
6752 <xarray.Dataset> Size: 160B
6753 Dimensions: (time: 10)
6754 Coordinates:
6755 * time (time) datetime64[us] 80B 2023-01-01 2023-01-02 ... 2023-01-10
6756 Data variables:
6757 data (time) float64 80B 1.0 nan nan nan 5.0 nan nan 8.0 nan 10.0
6758
6759 # filled dataset, fills NaN values by propagating values backward
6760
6761 >>> dataset.bfill(dim="time")
6762 <xarray.Dataset> Size: 160B
6763 Dimensions: (time: 10)
6764 Coordinates:
6765 * time (time) datetime64[us] 80B 2023-01-01 2023-01-02 ... 2023-01-10
6766 Data variables:
6767 data (time) float64 80B 1.0 5.0 5.0 5.0 5.0 8.0 8.0 8.0 10.0 10.0
6768
6769 # Limit the backward filling to a maximum of 2 consecutive NaN values
6770
6771 >>> dataset.bfill(dim="time", limit=2)
6772 <xarray.Dataset> Size: 160B
6773 Dimensions: (time: 10)
6774 Coordinates:
6775 * time (time) datetime64[us] 80B 2023-01-01 2023-01-02 ... 2023-01-10
6776 Data variables:
6777 data (time) float64 80B 1.0 nan 5.0 5.0 5.0 8.0 8.0 8.0 10.0 10.0
6778
6779 Returns
6780 -------
6781 Dataset
6782
6783 See Also
6784 --------

Callers 5

time_bfillMethod · 0.45
_get_nan_block_lengthsFunction · 0.45
test_upsampleMethod · 0.45
test_bfillMethod · 0.45

Calls 1

Tested by 3

test_upsampleMethod · 0.36
test_bfillMethod · 0.36