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

Method fillna

xarray/core/dataset.py:6436–6514  ·  view source on GitHub ↗

Fill missing values in this object. This operation follows the normal broadcasting and alignment rules that xarray uses for binary arithmetic, except the result is aligned to this object (``join='left'``) instead of aligned to the intersection of index coordinates (`

(self, value: Any)

Source from the content-addressed store, hash-verified

6434 return self.isel({dim: mask})
6435
6436 def fillna(self, value: Any) -> Self:
6437 """Fill missing values in this object.
6438
6439 This operation follows the normal broadcasting and alignment rules that
6440 xarray uses for binary arithmetic, except the result is aligned to this
6441 object (``join='left'``) instead of aligned to the intersection of
6442 index coordinates (``join='inner'``).
6443
6444 Parameters
6445 ----------
6446 value : scalar, ndarray, DataArray, dict or Dataset
6447 Used to fill all matching missing values in this dataset's data
6448 variables. Scalars, ndarrays or DataArrays arguments are used to
6449 fill all data with aligned coordinates (for DataArrays).
6450 Dictionaries or datasets match data variables and then align
6451 coordinates if necessary.
6452
6453 Returns
6454 -------
6455 Dataset
6456
6457 Examples
6458 --------
6459 >>> ds = xr.Dataset(
6460 ... {
6461 ... "A": ("x", [np.nan, 2, np.nan, 0]),
6462 ... "B": ("x", [3, 4, np.nan, 1]),
6463 ... "C": ("x", [np.nan, np.nan, np.nan, 5]),
6464 ... "D": ("x", [np.nan, 3, np.nan, 4]),
6465 ... },
6466 ... coords={"x": [0, 1, 2, 3]},
6467 ... )
6468 >>> ds
6469 <xarray.Dataset> Size: 160B
6470 Dimensions: (x: 4)
6471 Coordinates:
6472 * x (x) int64 32B 0 1 2 3
6473 Data variables:
6474 A (x) float64 32B nan 2.0 nan 0.0
6475 B (x) float64 32B 3.0 4.0 nan 1.0
6476 C (x) float64 32B nan nan nan 5.0
6477 D (x) float64 32B nan 3.0 nan 4.0
6478
6479 Replace all `NaN` values with 0s.
6480
6481 >>> ds.fillna(0)
6482 <xarray.Dataset> Size: 160B
6483 Dimensions: (x: 4)
6484 Coordinates:
6485 * x (x) int64 32B 0 1 2 3
6486 Data variables:
6487 A (x) float64 32B 0.0 2.0 0.0 0.0
6488 B (x) float64 32B 3.0 4.0 0.0 1.0
6489 C (x) float64 32B 0.0 0.0 0.0 5.0
6490 D (x) float64 32B 0.0 3.0 0.0 4.0
6491
6492 Replace all `NaN` elements in column ‘A’, ‘B’, ‘C’, and ‘D’, with 0, 1, 2, and 3 respectively.
6493

Callers 15

test_fillnaMethod · 0.95
test_fillnaMethod · 0.95
encodeMethod · 0.45
interpMethod · 0.45
combine_firstMethod · 0.45
_get_nan_block_lengthsFunction · 0.45
_reduceMethod · 0.45
reduceMethod · 0.45
test_groupby_fillnaMethod · 0.45
test_dask_is_lazyMethod · 0.45

Calls 1

keysMethod · 0.80

Tested by 12

test_fillnaMethod · 0.76
test_fillnaMethod · 0.76
test_groupby_fillnaMethod · 0.36
test_dask_is_lazyMethod · 0.36
test_fillnaMethod · 0.36
test_weightedMethod · 0.36