MCPcopy Index your code
hub / github.com/pydata/xarray / get_dummies

Method get_dummies

xarray/core/accessor_str.py:2770–2847  ·  view source on GitHub ↗

Return DataArray of dummy/indicator variables. Each string in the DataArray is split at `sep`. A new dimension is created with coordinates for each unique result, and the corresponding element of that dimension is `True` if that result is present and `False`

(
        self,
        dim: Hashable,
        sep: str | bytes | Any = "|",
    )

Source from the content-addressed store, hash-verified

2768 )
2769
2770 def get_dummies(
2771 self,
2772 dim: Hashable,
2773 sep: str | bytes | Any = "|",
2774 ) -> DataArray:
2775 """
2776 Return DataArray of dummy/indicator variables.
2777
2778 Each string in the DataArray is split at `sep`.
2779 A new dimension is created with coordinates for each unique result,
2780 and the corresponding element of that dimension is `True` if
2781 that result is present and `False` if not.
2782
2783 If `sep` is array-like, it is broadcast against the array and applied
2784 elementwise.
2785
2786 Parameters
2787 ----------
2788 dim : hashable
2789 Name for the dimension to place the results in.
2790 sep : str, default: "|".
2791 String to split on.
2792 If array-like, it is broadcast.
2793
2794 Returns
2795 -------
2796 dummies : array of bool
2797
2798 Examples
2799 --------
2800 Create a string array
2801
2802 >>> values = xr.DataArray(
2803 ... [
2804 ... ["a|ab~abc|abc", "ab", "a||abc|abcd"],
2805 ... ["abcd|ab|a", "abc|ab~abc", "|a"],
2806 ... ],
2807 ... dims=["X", "Y"],
2808 ... )
2809
2810 Extract dummy values
2811
2812 >>> values.str.get_dummies(dim="dummies")
2813 <xarray.DataArray (X: 2, Y: 3, dummies: 5)> Size: 30B
2814 array([[[ True, False, True, False, True],
2815 [False, True, False, False, False],
2816 [ True, False, True, True, False]],
2817 <BLANKLINE>
2818 [[ True, True, False, True, False],
2819 [False, False, True, False, True],
2820 [ True, False, False, False, False]]])
2821 Coordinates:
2822 * dummies (dummies) <U6 120B 'a' 'ab' 'abc' 'abcd' 'ab~abc'
2823 Dimensions without coordinates: X, Y
2824
2825 See Also
2826 --------
2827 pandas.Series.str.get_dummies

Callers 3

test_get_dummiesFunction · 0.80
test_get_dummies_emptyFunction · 0.80

Calls 6

_stringifyMethod · 0.95
_applyMethod · 0.95
_apply_str_ufuncFunction · 0.85
splitMethod · 0.80
expand_dimsMethod · 0.45
copyMethod · 0.45

Tested by 3

test_get_dummiesFunction · 0.64
test_get_dummies_emptyFunction · 0.64