Table Of Contents

Search

Enter search terms or a module, class or function name.

pandas.Series.str.cat

Series.str.cat(others=None, sep=None, na_rep=None)

Concatenate strings in the Series/Index with given separator.

Parameters:

others : list-like, or list of list-likes

If None, returns str concatenating strings of the Series

sep : string or None, default None

na_rep : string or None, default None

If None, NA in the series are ignored.

Returns:

concat : Series/Index of objects or str

Examples

When na_rep is None (default behavior), NaN value(s) in the Series are ignored.

>>> Series(['a','b',np.nan,'c']).str.cat(sep=' ')
'a b c'
>>> Series(['a','b',np.nan,'c']).str.cat(sep=' ', na_rep='?')
'a b ? c'

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

>>> Series(['a', 'b', 'c']).str.cat(['A', 'B', 'C'], sep=',')
0    a,A
1    b,B
2    c,C
dtype: object

Otherwise, strings in the Series are concatenated. Result will be a string.

>>> Series(['a', 'b', 'c']).str.cat(sep=',')
'a,b,c'

Also, you can pass a list of list-likes.

>>> Series(['a', 'b']).str.cat([['x', 'y'], ['1', '2']], sep=',')
0    a,x,1
1    b,y,2
dtype: object