MCPcopy
hub / github.com/pydata/xarray / ffill

Method ffill

xarray/core/dataset.py:6663–6725  ·  view source on GitHub ↗

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

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

Source from the content-addressed store, hash-verified

6661 return new
6662
6663 def ffill(self, dim: Hashable, limit: int | None = None) -> Self:
6664 """Fill NaN values by propagating values forward
6665
6666 *Requires bottleneck.*
6667
6668 Parameters
6669 ----------
6670 dim : Hashable
6671 Specifies the dimension along which to propagate values when filling.
6672 limit : int or None, optional
6673 The maximum number of consecutive NaN values to forward fill. In
6674 other words, if there is a gap with more than this number of
6675 consecutive NaNs, it will only be partially filled. Must be greater
6676 than 0 or None for no limit. Must be None or greater than or equal
6677 to axis length if filling along chunked axes (dimensions).
6678
6679 Examples
6680 --------
6681 >>> time = pd.date_range("2023-01-01", periods=10, freq="D")
6682 >>> data = np.array(
6683 ... [1, np.nan, np.nan, np.nan, 5, np.nan, np.nan, 8, np.nan, 10]
6684 ... )
6685 >>> dataset = xr.Dataset({"data": (("time",), data)}, coords={"time": time})
6686 >>> dataset
6687 <xarray.Dataset> Size: 160B
6688 Dimensions: (time: 10)
6689 Coordinates:
6690 * time (time) datetime64[us] 80B 2023-01-01 2023-01-02 ... 2023-01-10
6691 Data variables:
6692 data (time) float64 80B 1.0 nan nan nan 5.0 nan nan 8.0 nan 10.0
6693
6694 # Perform forward fill (ffill) on the dataset
6695
6696 >>> dataset.ffill(dim="time")
6697 <xarray.Dataset> Size: 160B
6698 Dimensions: (time: 10)
6699 Coordinates:
6700 * time (time) datetime64[us] 80B 2023-01-01 2023-01-02 ... 2023-01-10
6701 Data variables:
6702 data (time) float64 80B 1.0 1.0 1.0 1.0 5.0 5.0 5.0 8.0 8.0 10.0
6703
6704 # Limit the forward filling to a maximum of 2 consecutive NaN values
6705
6706 >>> dataset.ffill(dim="time", limit=2)
6707 <xarray.Dataset> Size: 160B
6708 Dimensions: (time: 10)
6709 Coordinates:
6710 * time (time) datetime64[us] 80B 2023-01-01 2023-01-02 ... 2023-01-10
6711 Data variables:
6712 data (time) float64 80B 1.0 1.0 1.0 nan 5.0 5.0 5.0 8.0 8.0 10.0
6713
6714 Returns
6715 -------
6716 Dataset
6717
6718 See Also
6719 --------
6720 Dataset.bfill

Callers 12

time_ffillMethod · 0.45
_get_nan_block_lengthsFunction · 0.45
_pushFunction · 0.45
test_upsampleMethod · 0.45
test_upsample_ndMethod · 0.45
test_ffill_functionsFunction · 0.45
test_ffill_datasetFunction · 0.45
test_bfill_datasetFunction · 0.45
test_ffillMethod · 0.45

Calls 1

Tested by 9

test_upsampleMethod · 0.36
test_upsample_ndMethod · 0.36
test_ffill_functionsFunction · 0.36
test_ffill_datasetFunction · 0.36
test_bfill_datasetFunction · 0.36
test_ffillMethod · 0.36