xarray.Dataset

class xarray.Dataset(data_vars=None, coords=None, attrs=None)

A multi-dimensional, in memory, array database.

A dataset resembles an in-memory representation of a NetCDF file, and consists of variables, coordinates and attributes which together form a self describing dataset.

Dataset implements the mapping interface with keys given by variable names and values given by DataArray objects for each variable name.

One dimensional variables with name equal to their dimension are index coordinates used for label based indexing.

__init__(self, data_vars: Mapping[Hashable, Any] = None, coords: Mapping[Hashable, Any] = None, attrs: Mapping[Hashable, Any] = None)

To load data from a file or file-like object, use the open_dataset function.

Parameters
  • data_vars (dict-like, optional) –

    A mapping from variable names to DataArray objects, Variable objects or to tuples of the form (dims, data[, attrs]) which can be used as arguments to create a new Variable. Each dimension must have the same length in all variables in which it appears.

    The following notations are accepted:

    • mapping {var name: DataArray}

    • mapping {var name: Variable}

    • mapping {var name: (dimension name, array-like)}

    • mapping {var name: (tuple of dimension names, array-like)}

    • mapping {dimension name: array-like} (it will be automatically moved to coords, see below)

    Each dimension must have the same length in all variables in which it appears.

  • coords (dict-like, optional) –

    Another mapping in similar form as the data_vars argument, except the each item is saved on the dataset as a “coordinate”. These variables have an associated meaning: they describe constant/fixed/independent quantities, unlike the varying/measured/dependent quantities that belong in variables. Coordinates values may be given by 1-dimensional arrays or scalars, in which case dims do not need to be supplied: 1D arrays will be assumed to give index values along the dimension with the same name.

    The following notations are accepted:

    • mapping {coord name: DataArray}

    • mapping {coord name: Variable}

    • mapping {coord name: (dimension name, array-like)}

    • mapping {coord name: (tuple of dimension names, array-like)}

    • mapping {dimension name: array-like} (the dimension name is implicitly set to be the same as the coord name)

    The last notation implies that the coord name is the same as the dimension name.

  • attrs (dict-like, optional) – Global attributes to save on this dataset.

Methods

__init__(self, data_vars, Any] = None, …)

To load data from a file or file-like object, use the open_dataset function.

all(self[, dim])

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

any(self[, dim])

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

apply(self, func, keep_attrs, args, \*\*kwargs)

Backward compatible implementation of map

argmax(self[, dim, skipna])

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

argmin(self[, dim, skipna])

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

argsort([axis, kind, order])

Returns the indices that would sort this array.

assign(self, variables, Any] = None, …)

Assign new data variables to a Dataset, returning a new object with all the original variables in addition to the new ones.

assign_attrs(self, \*args, \*\*kwargs)

Assign new attrs to this object.

assign_coords(self[, coords])

Assign new coordinates to this object.

astype(dtype[, order, casting, subok, copy])

Copy of the array, cast to a specified type.

bfill(self, dim, limit)

Fill NaN values by propogating values backward

broadcast_equals(self, other)

Two Datasets are broadcast equal if they are equal after broadcasting all variables against each other.

broadcast_like(self, other, ForwardRef], exclude)

Broadcast this DataArray against another Dataset or DataArray.

chunk(self, chunks, numbers.Number, …)

Coerce all arrays in this dataset into dask arrays with the given chunks.

clip([min, max, out])

Return an array whose values are limited to [min, max].

close(self)

Close any files linked to this object

coarsen(self, dim, int] = None, boundary, …)

Coarsen object.

combine_first(self, other)

Combine two Datasets, default to data_vars of self.

compute(self, \*\*kwargs)

Manually trigger loading and/or computation of this dataset’s data from disk or a remote source into memory and return a new dataset.

conj()

Complex-conjugate all elements.

conjugate()

Return the complex conjugate, element-wise.

copy(self, deep, data)

Returns a copy of this dataset.

count(self[, dim])

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

cumprod(self[, dim, skipna])

Apply cumprod along some dimension of Dataset.

cumsum(self[, dim, skipna])

Apply cumsum along some dimension of Dataset.

diff(self, dim[, n, label])

Calculate the n-th order discrete difference along given axis.

differentiate(self, coord[, edge_order, …])

Differentiate with the second order accurate central differences.

drop(self[, labels, dim, errors])

Backward compatible method based on drop_vars and drop_sel

drop_dims(self, drop_dims, …)

Drop dimensions and associated variables from this dataset.

drop_sel(self[, labels, errors])

Drop index labels from this dataset.

drop_vars(self, names, Iterable[Hashable]], …)

Drop variables from this dataset.

dropna(self, dim, how, thresh, subset)

Returns a new dataset with dropped labels for missing values along the provided dimension.

dump_to_store(self, store, \*\*kwargs)

Store dataset contents to a backends.*DataStore object.

equals(self, other)

Two Datasets are equal if they have matching variables and coordinates, all of which are equal.

expand_dims(self, dim, Hashable, …)

Return a new object with an additional axis (or axes) inserted at the corresponding position in the array shape.

ffill(self, dim, limit)

Fill NaN values by propogating values forward

fillna(self, value)

Fill missing values in this object.

filter_by_attrs(self, \*\*kwargs)

Returns a Dataset with variables that match specific conditions.

from_dataframe(dataframe, sparse)

Convert a pandas.DataFrame into an xarray.Dataset

from_dict(d)

Convert a dictionary into an xarray.Dataset.

get(self, key[, default])

get_index(self, key)

Get an index for a dimension, with fall-back to a default RangeIndex

groupby(self, group, squeeze, restore_coord_dims)

Returns a GroupBy object for performing grouped operations.

groupby_bins(self, group, bins, right[, labels])

Returns a GroupBy object for performing grouped operations.

head(self, indexers, int], int] = None, …)

Returns a new dataset with the first n values of each array for the specified dimension(s).

identical(self, other)

Like equals, but also checks all dataset attributes and the attributes on all variables and coordinates.

info(self[, buf])

Concise summary of a Dataset variables and attributes.

integrate(self, coord[, datetime_unit])

integrate the array with the trapezoidal rule.

interp(self, coords, Any] = None, method, …)

Multidimensional interpolation of Dataset.

interp_like(self, other, ForwardRef], …)

Interpolate this object onto the coordinates of another object, filling the out of range values with NaN.

interpolate_na(self, dim, method, limit, …)

Fill in NaNs by interpolating according to different methods.

isel(self, indexers, Any] = None, drop, …)

Returns a new dataset with each array indexed along the specified dimension(s).

isin(self, test_elements)

Tests each value in the array for whether it is in test elements.

isnull(self, \*args, \*\*kwargs)

items(self)

keys(self)

load(self, \*\*kwargs)

Manually trigger loading and/or computation of this dataset’s data from disk or a remote source into memory and return this dataset.

load_store(store[, decoder])

Create a new dataset from the contents of a backends.*DataStore object

map(self, func, keep_attrs, args, \*\*kwargs)

Apply a function to each variable in this dataset

map_blocks(self, func, args, kwargs, Any] = None)

Apply a function to each chunk of this Dataset.

max(self[, dim, skipna])

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

mean(self[, dim, skipna])

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

median(self[, dim, skipna])

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

merge(self, other, ForwardRef], inplace, …)

Merge the arrays of two datasets into a single dataset.

min(self[, dim, skipna])

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

notnull(self, \*args, \*\*kwargs)

pad(self, pad_width, Union[int, Tuple[int, …)

Pad this dataset along one or more dimensions.

persist(self, \*\*kwargs)

Trigger computation, keeping data as dask arrays

pipe(self, func, ~T], Tuple[Callable[…, …)

Apply func(self, *args, **kwargs)

prod(self[, dim, skipna])

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

quantile(self, q[, dim, interpolation, …])

Compute the qth quantile of the data along the specified dimension.

rank(self, dim[, pct, keep_attrs])

Ranks the data.

reduce(self, func, dim, …)

Reduce this dataset by applying func along some dimension(s).

reindex(self, indexers, Any] = None, method, …)

Conform this object onto a new set of indexes, filling in missing values with fill_value.

reindex_like(self, other, ForwardRef], …)

Conform this object onto the indexes of another object, filling in missing values with fill_value.

rename(self, name_dict, Hashable] = None, …)

Returns a new object with renamed variables and dimensions.

rename_dims(self, dims_dict, …)

Returns a new object with renamed dimensions only.

rename_vars(self, name_dict, …)

Returns a new object with renamed variables including coordinates

reorder_levels(self, dim_order, …)

Rearrange index levels using input order.

resample(self, indexer, str] = None[, …])

Returns a Resample object for performing resampling operations.

reset_coords(self, names, drop, inplace)

Given names of coordinates, reset them to become variables

reset_index(self, dims_or_levels, …)

Reset the specified index(es) or multi-index level(s).

roll(self[, shifts, roll_coords])

Roll this dataset by an offset along one or more dimensions.

rolling(self, dim, int] = None, min_periods, …)

Rolling window object.

rolling_exp(self, window, int] = None, …)

Exponentially-weighted moving window.

round(self, \*args, \*\*kwargs)

sel(self, indexers, Any] = None, method, …)

Returns a new dataset with each array indexed by tick labels along the specified dimension(s).

set_coords(self, names, inplace)

Given names of one or more variables, set them as coordinates

set_index(self, indexes, Union[Hashable, …)

Set Dataset (multi-)indexes using one or more existing coordinates or variables.

shift(self[, shifts, fill_value])

Shift this dataset by an offset along one or more dimensions.

sortby(self, variables[, ascending])

Sort object by labels or values (along an axis).

squeeze(self, dim, Iterable[Hashable], …)

Return a new object with squeezed data.

stack(self, dimensions, …)

Stack any number of existing dimensions into a single new dimension.

std(self[, dim, skipna])

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

sum(self[, dim, skipna])

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

swap_dims(self, dims_dict, Hashable], inplace)

Returns a new object with swapped dimensions.

tail(self, indexers, int], int] = None, …)

Returns a new dataset with the last n values of each array for the specified dimension(s).

thin(self, indexers, int], int] = None, …)

Returns a new dataset with each array indexed along every n-th value for the specified dimension(s)

to_array(self[, dim, name])

Convert this dataset into an xarray.DataArray

to_dask_dataframe(self[, dim_order, set_index])

Convert this dataset into a dask.dataframe.DataFrame.

to_dataframe(self)

Convert this dataset into a pandas.DataFrame.

to_dict(self[, data])

Convert this dataset to a dictionary following xarray naming conventions.

to_netcdf(self[, path])

Write dataset contents to a netCDF file.

to_stacked_array(self, new_dim, sample_dims, …)

Combine variables of differing dimensionality into a DataArray without broadcasting.

to_zarr(self, store, str, …[, synchronizer])

Write dataset contents to a zarr group.

transpose(self, \*dims)

Return a new Dataset object with all array dimensions transposed.

unify_chunks(self)

Unify chunk size along all chunked dimensions of this Dataset.

unstack(self, dim, …)

Unstack existing dimensions corresponding to MultiIndexes into multiple new dimensions.

update(self, other, inplace)

Update this dataset’s variables with those from another dataset.

values(self)

var(self[, dim, skipna])

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

weighted(self, weights)

Weighted operations.

where(self, cond[, other])

Filter elements from this object according to a condition.

Attributes

attrs

Dictionary of global attributes on this dataset

chunks

Block dimensions for this dataset’s data or None if it’s not a dask array.

coords

Dictionary of xarray.DataArray objects corresponding to coordinate variables

data_vars

Dictionary of DataArray objects corresponding to data variables

dims

Mapping from dimension names to lengths.

encoding

Dictionary of global encoding attributes on this dataset

imag

indexes

Mapping of pandas.Index objects used for label based indexing

loc

Attribute for location based indexing.

nbytes

plot

Access plotting functions for Datasets.

real

sizes

Mapping from dimension names to lengths.

variables

Low level interface to Dataset contents as dict of Variable objects.