cudf.core.column.string.StringMethods.cat#

StringMethods.cat(sep: str | None = None, na_rep: str | None = None) str[source]#
StringMethods.cat(others, sep: str | None = None, na_rep: str | None = None) SeriesOrIndex | 'cudf.core.column.string.StringColumn'

Concatenate strings in the Series/Index with given separator.

If others is specified, this function concatenates the Series/Index and elements of others element-wise. If others is not passed, then all values in the Series/Index are concatenated into a single string with a given sep.

Parameters:
othersSeries or List of str

Strings to be appended. The number of strings must match size() of this instance. This must be either a Series of string dtype or a Python list of strings.

sepstr

If specified, this separator will be appended to each string before appending the others.

na_repstr

This character will take the place of any null strings (not empty strings) in either list.

  • If na_rep is None, and others is None, missing values in the Series/Index are omitted from the result.

  • If na_rep is None, and others is not None, a row containing a missing value in any of the columns (before concatenation) will have a missing value in the result.

Returns:
concatstr or Series/Index of str dtype

If others is None, str is returned, otherwise a Series/Index (same type as caller) of str dtype is returned.

Examples

>>> import cudf
>>> s = cudf.Series(['a', 'b', None, 'd'])
>>> s.str.cat(sep=' ')
'a b d'

By default, NA values in the Series are ignored. Using na_rep, they can be given a representation:

>>> s.str.cat(sep=' ', na_rep='?')
'a b ? d'

If others is specified, corresponding values are concatenated with the separator. Result will be a Series of strings.

>>> s.str.cat(['A', 'B', 'C', 'D'], sep=',')
0     a,A
1     b,B
2    <NA>
3     d,D
dtype: object

Missing values will remain missing in the result, but can again be represented using na_rep

>>> s.str.cat(['A', 'B', 'C', 'D'], sep=',', na_rep='-')
0    a,A
1    b,B
2    -,C
3    d,D
dtype: object

If sep is not specified, the values are concatenated without separation.

>>> s.str.cat(['A', 'B', 'C', 'D'], na_rep='-')
0    aA
1    bB
2    -C
3    dD
dtype: object