xarray.core.groupby.DataArrayGroupBy.var
xarray.core.groupby.DataArrayGroupBy.var#
- DataArrayGroupBy.var(dim=None, *, skipna=None, ddof=0, keep_attrs=None, **kwargs)[source]#
Reduce this DataArray’s data by applying
varalong some dimension(s).- Parameters
dim (
str,IterableofHashable,"..."orNone, default:None) – Name of dimension[s] along which to applyvar. For e.g.dim="x"ordim=["x", "y"]. If None, will reduce over the GroupBy dimensions. If “…”, will reduce over all dimensions.skipna (
boolorNone, optional) – If True, skip missing values (as marked by NaN). By default, only skips missing values for float dtypes; other dtypes either do not have a sentinel missing value (int) orskipna=Truehas not been implemented (object, datetime64 or timedelta64).ddof (
int, default:0) – “Delta Degrees of Freedom”: the divisor used in the calculation isN - ddof, whereNrepresents the number of elements.keep_attrs (
boolorNone, optional) – If True,attrswill be copied from the original object to the new one. If False, the new object will be returned without attributes.**kwargs (
Any) – Additional keyword arguments passed on to the appropriate array function for calculatingvaron this object’s data. These could include dask-specific kwargs likesplit_every.
- Returns
reduced (
DataArray) – New DataArray withvarapplied to its data and the indicated dimension(s) removed
See also
numpy.var,dask.array.var,DataArray.var- GroupBy: Group and Bin Data
User guide on groupby operations.
Notes
Non-numeric variables will be removed prior to reducing.
Examples
>>> da = xr.DataArray( ... np.array([1, 2, 3, 1, 2, np.nan]), ... dims="time", ... coords=dict( ... time=("time", pd.date_range("01-01-2001", freq="M", periods=6)), ... labels=("time", np.array(["a", "b", "c", "c", "b", "a"])), ... ), ... ) >>> da <xarray.DataArray (time: 6)> array([ 1., 2., 3., 1., 2., nan]) Coordinates: * time (time) datetime64[ns] 2001-01-31 2001-02-28 ... 2001-06-30 labels (time) <U1 'a' 'b' 'c' 'c' 'b' 'a'
>>> da.groupby("labels").var() <xarray.DataArray (labels: 3)> array([0., 0., 1.]) Coordinates: * labels (labels) object 'a' 'b' 'c'
Use
skipnato control whether NaNs are ignored.>>> da.groupby("labels").var(skipna=False) <xarray.DataArray (labels: 3)> array([nan, 0., 1.]) Coordinates: * labels (labels) object 'a' 'b' 'c'
Specify
ddof=1for an unbiased estimate.>>> da.groupby("labels").var(skipna=True, ddof=1) <xarray.DataArray (labels: 3)> array([nan, 0., 2.]) Coordinates: * labels (labels) object 'a' 'b' 'c'