DataArray.str.join(dim=None, sep='')[source]#

Concatenate strings in a DataArray along a particular dimension.

An optional separator sep can also be specified. If sep is array-like, it is broadcast against the array and applied elementwise.

  • dim (hashable, optional) – Dimension along which the strings should be concatenated. Only one dimension is allowed at a time. Optional for 0D or 1D DataArrays, required for multidimensional DataArrays.

  • sep (str or array-like, default: "") – Separator to use between strings. It is broadcast in the same way as the other input strings. If array-like, its dimensions will be placed at the end of the output array dimensions.


joined (same type as values)


Create an array

>>> values = xr.DataArray(
...     [["a", "bab", "abc"], ["abcd", "", "abcdef"]],
...     dims=["X", "Y"],
... )

Determine the separator

>>> seps = xr.DataArray(
...     ["-", "_"],
...     dims=["ZZ"],
... )

Join the strings along a given dimension

>>> values.str.join(dim="Y", sep=seps)
<xarray.DataArray (X: 2, ZZ: 2)>
array([['a-bab-abc', 'a_bab_abc'],
       ['abcd--abcdef', 'abcd__abcdef']], dtype='<U12')
Dimensions without coordinates: X, ZZ