xarray.Dataset.mean (original) (raw)

Dataset.mean(dim=None, *, skipna=None, keep_attrs=None, **kwargs)[source]#

Reduce this Dataset’s data by applying mean along some dimension(s).

Parameters:

Returns:

reduced (Dataset) – New Dataset with mean applied to its data and the indicated dimension(s) removed

Notes

Non-numeric variables will be removed prior to reducing.

Examples

da = xr.DataArray( ... np.array([1, 2, 3, 0, 2, np.nan]), ... dims="time", ... coords=dict( ... time=("time", pd.date_range("2001-01-01", freq="ME", periods=6)), ... labels=("time", np.array(["a", "b", "c", "c", "b", "a"])), ... ), ... ) ds = xr.Dataset(dict(da=da)) ds <xarray.Dataset> Size: 120B Dimensions: (time: 6) Coordinates:

ds.mean() <xarray.Dataset> Size: 8B Dimensions: () Data variables: da float64 8B 1.6

Use skipna to control whether NaNs are ignored.

ds.mean(skipna=False) <xarray.Dataset> Size: 8B Dimensions: () Data variables: da float64 8B nan