Skip to content

Commit

Permalink
xarray.dataset.ffill
Browse files Browse the repository at this point in the history
  • Loading branch information
harshitha1201 committed Jun 20, 2023
1 parent 760aa4a commit 848a5fd
Showing 1 changed file with 28 additions and 0 deletions.
28 changes: 28 additions & 0 deletions xarray/core/dataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -6025,6 +6025,34 @@ def ffill(self: T_Dataset, dim: Hashable, limit: int | None = None) -> T_Dataset
than 0 or None for no limit. Must be None or greater than or equal
to axis length if filling along chunked axes (dimensions).
Example
-------
# Create a sample dataset with missing values
>>> time = pd.date_range("2023-01-01", periods=10, freq="D")
>>> data = np.array([1, np.nan, 3, np.nan, 5, 6, np.nan, 8, np.nan, 10])
>>> dataset = xr.Dataset({"data": (("time",), data)}, coords={"time": time})
# Perform forward fill (ffill) on the dataset
>>> filled_dataset = dataset.ffill(dim="time")
# Print the original dataset
>>> dataset
<xarray.Dataset>
Dimensions: (time: 10)
Coordinates:
* time (time) datetime64[ns] 2023-01-01 2023-01-02 ... 2023-01-10
Data variables:
data (time) float64 1.0 nan 3.0 nan 5.0 6.0 nan 8.0 nan 10.0
# Print the filled dataset, fills NaN values by propagating values forward
>>> filled_dataset
<xarray.Dataset>
Dimensions: (time: 10)
Coordinates:
* time (time) datetime64[ns] 2023-01-01 2023-01-02 ... 2023-01-10
Data variables:
data (time) float64 1.0 1.0 3.0 3.0 5.0 6.0 6.0 8.0 8.0 10.0
Returns
-------
Dataset
Expand Down

0 comments on commit 848a5fd

Please sign in to comment.