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)
| 3498 | return self._from_temp_dataset(ds) |
| 3499 | |
| 3500 | def fillna(self, value: Any) -> Self: |
| 3501 | """Fill missing values in this object. |
| 3502 | |
| 3503 | This operation follows the normal broadcasting and alignment rules that |
| 3504 | xarray uses for binary arithmetic, except the result is aligned to this |
| 3505 | object (``join='left'``) instead of aligned to the intersection of |
| 3506 | index coordinates (``join='inner'``). |
| 3507 | |
| 3508 | Parameters |
| 3509 | ---------- |
| 3510 | value : scalar, ndarray or DataArray |
| 3511 | Used to fill all matching missing values in this array. If the |
| 3512 | argument is a DataArray, it is first aligned with (reindexed to) |
| 3513 | this array. |
| 3514 | |
| 3515 | Returns |
| 3516 | ------- |
| 3517 | filled : DataArray |
| 3518 | |
| 3519 | Examples |
| 3520 | -------- |
| 3521 | >>> da = xr.DataArray( |
| 3522 | ... np.array([1, 4, np.nan, 0, 3, np.nan]), |
| 3523 | ... dims="Z", |
| 3524 | ... coords=dict( |
| 3525 | ... Z=("Z", np.arange(6)), |
| 3526 | ... height=("Z", np.array([0, 10, 20, 30, 40, 50])), |
| 3527 | ... ), |
| 3528 | ... ) |
| 3529 | >>> da |
| 3530 | <xarray.DataArray (Z: 6)> Size: 48B |
| 3531 | array([ 1., 4., nan, 0., 3., nan]) |
| 3532 | Coordinates: |
| 3533 | * Z (Z) int64 48B 0 1 2 3 4 5 |
| 3534 | height (Z) int64 48B 0 10 20 30 40 50 |
| 3535 | |
| 3536 | Fill all NaN values with 0: |
| 3537 | |
| 3538 | >>> da.fillna(0) |
| 3539 | <xarray.DataArray (Z: 6)> Size: 48B |
| 3540 | array([1., 4., 0., 0., 3., 0.]) |
| 3541 | Coordinates: |
| 3542 | * Z (Z) int64 48B 0 1 2 3 4 5 |
| 3543 | height (Z) int64 48B 0 10 20 30 40 50 |
| 3544 | |
| 3545 | Fill NaN values with corresponding values in array: |
| 3546 | |
| 3547 | >>> da.fillna(np.array([2, 9, 4, 2, 8, 9])) |
| 3548 | <xarray.DataArray (Z: 6)> Size: 48B |
| 3549 | array([1., 4., 4., 0., 3., 9.]) |
| 3550 | Coordinates: |
| 3551 | * Z (Z) int64 48B 0 1 2 3 4 5 |
| 3552 | height (Z) int64 48B 0 10 20 30 40 50 |
| 3553 | """ |
| 3554 | if utils.is_dict_like(value): |
| 3555 | raise TypeError( |
| 3556 | "cannot provide fill value as a dictionary with fillna on a DataArray" |
| 3557 | ) |
no outgoing calls