xarray.merge

xarray.merge(objects, compat='no_conflicts', join='outer', fill_value=<NA>)

Merge any number of xarray objects into a single Dataset as variables.

Parameters
objectsIterable[Union[xarray.Dataset, xarray.DataArray, dict]]

Merge together all variables from these objects. If any of them are DataArray objects, they must have a name.

compat{‘identical’, ‘equals’, ‘broadcast_equals’, ‘no_conflicts’}, optional

String indicating how to compare variables of the same name for potential conflicts:

  • ‘broadcast_equals’: all values must be equal when variables are broadcast against each other to ensure common dimensions.

  • ‘equals’: all values and dimensions must be the same.

  • ‘identical’: all values, dimensions and attributes must be the same.

  • ‘no_conflicts’: only values which are not null in both datasets must be equal. The returned dataset then contains the combination of all non-null values.

join{‘outer’, ‘inner’, ‘left’, ‘right’, ‘exact’}, optional

How to combine objects with different indexes.

fill_valuescalar, optional

Value to use for newly missing values

Returns
Dataset

Dataset with combined variables from each object.

Raises
xarray.MergeError

If any variables with the same name have conflicting values.

See also

concat

Examples

>>> arrays = [xr.DataArray(n, name='var%d' % n) for n in range(5)]
>>> xr.merge(arrays)
<xarray.Dataset>
Dimensions:  ()
Coordinates:
    *empty*
Data variables:
    var0     int64 0
    var1     int64 1
    var2     int64 2
    var3     int64 3
    var4     int64 4