# xarray.DataArray.bfill

#### DataArray.bfill(dim, limit=None)[[source]](https://github.com/pydata/xarray/blob/main/xarray/core/dataarray.py#L3896-L3978)

Fill NaN values by propagating values backward.

*Requires bottleneck.*

* **Parameters:**
  * **dim** ([`str`](xarray.DataArray.str.html.md#xarray.DataArray.str)) – 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), *default*: [`None`](https://docs.python.org/3/builtins/constants.html#None)) – The maximum number of consecutive NaN values to backward 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).
* **Returns:**
  **filled** ([`DataArray`](xarray.DataArray.html.md#xarray.DataArray))

### Examples

<div class="try_examples_button_container"><button class="try_examples_button" onclick="window.tryExamplesShowIframe('d13265b3-8fa1-47c3-a3a9-0b22305e522f','073ec06f-d64c-40ee-8635-14f1ec4c2921','7befdd25-6481-4299-99e8-bd1d562ac202','../lite/tree/../notebooks/index.html?path=c1e3b32a_b3ea_4043_a09c_b4602d9e2fc7.ipynb','None')">Try it in your browser!</button></div>
```pycon
>>> temperature = np.array(
...     [
...         [0, 1, 3],
...         [0, np.nan, 5],
...         [5, np.nan, np.nan],
...         [3, np.nan, np.nan],
...         [np.nan, 2, 0],
...     ]
... )
>>> da = xr.DataArray(
...     data=temperature,
...     dims=["Y", "X"],
...     coords=dict(
...         lat=("Y", np.array([-20.0, -20.25, -20.50, -20.75, -21.0])),
...         lon=("X", np.array([10.0, 10.25, 10.5])),
...     ),
... )
>>> da
<xarray.DataArray (Y: 5, X: 3)> Size: 120B
array([[ 0.,  1.,  3.],
       [ 0., nan,  5.],
       [ 5., nan, nan],
       [ 3., nan, nan],
       [nan,  2.,  0.]])
Coordinates:
    lat      (Y) float64 40B -20.0 -20.25 -20.5 -20.75 -21.0
    lon      (X) float64 24B 10.0 10.25 10.5
Dimensions without coordinates: Y, X
```

Fill all NaN values:

```pycon
>>> da.bfill(dim="Y", limit=None)
<xarray.DataArray (Y: 5, X: 3)> Size: 120B
array([[ 0.,  1.,  3.],
       [ 0.,  2.,  5.],
       [ 5.,  2.,  0.],
       [ 3.,  2.,  0.],
       [nan,  2.,  0.]])
Coordinates:
    lat      (Y) float64 40B -20.0 -20.25 -20.5 -20.75 -21.0
    lon      (X) float64 24B 10.0 10.25 10.5
Dimensions without coordinates: Y, X
```

Fill only the first of consecutive NaN values:

```pycon
>>> da.bfill(dim="Y", limit=1)
<xarray.DataArray (Y: 5, X: 3)> Size: 120B
array([[ 0.,  1.,  3.],
       [ 0., nan,  5.],
       [ 5., nan, nan],
       [ 3.,  2.,  0.],
       [nan,  2.,  0.]])
Coordinates:
    lat      (Y) float64 40B -20.0 -20.25 -20.5 -20.75 -21.0
    lon      (X) float64 24B 10.0 10.25 10.5
Dimensions without coordinates: Y, X
```

<div id="7befdd25-6481-4299-99e8-bd1d562ac202" class="try_examples_outer_iframe  hidden"><div class="try_examples_button_container"><button class="try_examples_button" onclick="window.tryExamplesHideIframe('d13265b3-8fa1-47c3-a3a9-0b22305e522f','7befdd25-6481-4299-99e8-bd1d562ac202')">Go Back</button><button class="try_examples_button" onclick="window.openInNewTab('d13265b3-8fa1-47c3-a3a9-0b22305e522f','7befdd25-6481-4299-99e8-bd1d562ac202')">Open In Tab</button></div><div id="073ec06f-d64c-40ee-8635-14f1ec4c2921" class="jupyterlite_sphinx_iframe_container"></div></div><script>document.addEventListener("DOMContentLoaded", function() {window.loadTryExamplesConfig("../try_examples.json");});</script>
