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
  • objects (Iterable[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', 'override'}, 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.

    • ’override’: skip comparing and pick variable from first dataset

  • join ({'outer', 'inner', 'left', 'right', 'exact'}, optional) –

    String indicating how to combine differing indexes in objects.

    • ’outer’: use the union of object indexes

    • ’inner’: use the intersection of object indexes

    • ’left’: use indexes from the first object with each dimension

    • ’right’: use indexes from the last object with each dimension

    • ’exact’: instead of aligning, raise ValueError when indexes to be aligned are not equal

    • ’override’: if indexes are of same size, rewrite indexes to be those of the first object with that dimension. Indexes for the same dimension must have the same size in all objects.

  • fill_value (scalar, optional) – Value to use for newly missing values

Returns

Dataset with combined variables from each object.

Return type

Dataset

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
Raises

xarray.MergeError – If any variables with the same name have conflicting values.

See also

concat()