# xarray.Dataset.ffill

#### Dataset.ffill(dim, limit=None)[[source]](https://github.com/pydata/xarray/blob/main/xarray/core/dataset.py#L6756-L6818)

Fill NaN values by propagating values forward

*Requires bottleneck.*

* **Parameters:**
  * **dim** (`Hashable`) – Specifies the dimension along which to propagate values when filling.
  * **limit** ([`int`](https://docs.python.org/3/builtins/functions.html#int) or [`None`](https://docs.python.org/3/builtins/constants.html#None), *optional*) – The maximum number of consecutive NaN values to forward fill. In
    other words, if there is a gap with more than this number of
    consecutive NaNs, it will only be partially filled. Must be greater
    than 0 or None for no limit. Must be None or greater than or equal
    to axis length if filling along chunked axes (dimensions).

### Examples

<div class="try_examples_button_container"><button class="try_examples_button" onclick="window.tryExamplesShowIframe('5648dd99-319f-4cb2-9628-abecc7fed466','9eaee14d-f6c9-4529-b9e7-270f3d76e09f','a1a42885-b2e8-44e4-8ca1-722e493ae6a5','../lite/tree/../notebooks/index.html?path=8dfad798_5bdf_4125_a0ba_77cdf62c0e8d.ipynb','None')">Try it in your browser!</button></div>
```pycon
>>> time = pd.date_range("2023-01-01", periods=10, freq="D")
>>> data = np.array(
...     [1, np.nan, np.nan, np.nan, 5, np.nan, np.nan, 8, np.nan, 10]
... )
>>> dataset = xr.Dataset({"data": (("time",), data)}, coords={"time": time})
>>> dataset
<xarray.Dataset> Size: 160B
Dimensions:  (time: 10)
Coordinates:
  * time     (time) datetime64[us] 80B 2023-01-01 2023-01-02 ... 2023-01-10
Data variables:
    data     (time) float64 80B 1.0 nan nan nan 5.0 nan nan 8.0 nan 10.0
```

# Perform forward fill (ffill) on the dataset

```pycon
>>> dataset.ffill(dim="time")
<xarray.Dataset> Size: 160B
Dimensions:  (time: 10)
Coordinates:
  * time     (time) datetime64[us] 80B 2023-01-01 2023-01-02 ... 2023-01-10
Data variables:
    data     (time) float64 80B 1.0 1.0 1.0 1.0 5.0 5.0 5.0 8.0 8.0 10.0
```

# Limit the forward filling to a maximum of 2 consecutive NaN values

```pycon
>>> dataset.ffill(dim="time", limit=2)
<xarray.Dataset> Size: 160B
Dimensions:  (time: 10)
Coordinates:
  * time     (time) datetime64[us] 80B 2023-01-01 2023-01-02 ... 2023-01-10
Data variables:
    data     (time) float64 80B 1.0 1.0 1.0 nan 5.0 5.0 5.0 8.0 8.0 10.0
```

<div id="a1a42885-b2e8-44e4-8ca1-722e493ae6a5" class="try_examples_outer_iframe  hidden"><div class="try_examples_button_container"><button class="try_examples_button" onclick="window.tryExamplesHideIframe('5648dd99-319f-4cb2-9628-abecc7fed466','a1a42885-b2e8-44e4-8ca1-722e493ae6a5')">Go Back</button><button class="try_examples_button" onclick="window.openInNewTab('5648dd99-319f-4cb2-9628-abecc7fed466','a1a42885-b2e8-44e4-8ca1-722e493ae6a5')">Open In Tab</button></div><div id="9eaee14d-f6c9-4529-b9e7-270f3d76e09f" class="jupyterlite_sphinx_iframe_container"></div></div><script>document.addEventListener("DOMContentLoaded", function() {window.loadTryExamplesConfig("../try_examples.json");});</script>
* **Returns:**
  [`Dataset`](xarray.Dataset.html.md#xarray.Dataset)

#### SEE ALSO
[`Dataset.bfill`](xarray.Dataset.bfill.html.md#xarray.Dataset.bfill)
