Xarray Dataarray - How to Fillna Using Ffill?

What would be the equivalent, if there is one, of the Panel.ffill(axis=None, inplace=False, limit=None, downcast=None) or Panel.fillna(value=None, method=None, ...) for a DataArray with three dimensions?

DataArray has a fillna method, but only takes a value as a parameter. DataArray.fillna(value).

Example: how to fill the nan value using the previous non nan value with existing methods of xarray?

import numpy as np
import pandas as pd
import xarray as xr

data = np.random.rand(10, 3,3)
data[2,0,1]=np.NaN 

times = pd.date_range('2000-01-01', periods=10)
dim1 = ['A1', 'A2', 'A3']
dim2 = ['B1', 'B2', 'B3']

xrda = xr.DataArray(data, coords=[times, dim1, dim2], dims=['time', 'dim1', 'dim2'])
1
Sophia Al-Mansoor

Sophia Al-Mansoor

Global Business & E-Commerce Reporter

Sophia analyzes international trade, startup ecosystems, retail transformation, and supply chain logistics for modern digital publications.

Share this article